Apache2 インストール
Apache2インストール
[root@centos ~]# yum -y install httpd
httpd.conf編集
[root@centos ~]# vi /etc/httpd/conf/httpd.conf
ServerAdmin root@localhost
↓
ServerAdmin postmaster@server-manual.com ←変更(管理者のメールアドレスを記入)
#ServerName www.example.com:80
↓
ServerName server-manual.com:80 ←コメント解除&変更(サーバー名を記入)
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
↓
Options Includes ExecCGI FollowSymLinks ←変更(CGI,SSIを許可。ファイル一覧表示禁止)
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
↓
AllowOverride All ←変更(.htaccessを許可)
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
↓
DirectoryIndex index.html index.htm index.cgi ←変更(index.htm index.cgiを許可)
</IfModule>
ErrorLog logs/error_log
↓
ErrorLog /var/log/httpd/error_log ←変更(エラーログ)
<IfModule log_config_module>
CustomLog logs/access_log combined
↓
SetEnvIf Request_URI "default\.ida" nolog
SetEnvIf Request_URI "cmd\.exe" nolog
SetEnvIf Request_URI "root\.exe" nolog
SetEnvIf Request_URI "Admin\.dll" nolog
SetEnvIf Request_URI "NULL\.IDA" nolog
SetEnvIf Request_URI "\.(gif)|(jpg)|(png)|(ico)|(css)$" nolog
CustomLog /var/log/httpd/access_log combined env=!nolog ←変更(アクセスログ)
</IfModule>
<IfModule mime_module>
#AddHandler cgi-script .cgi
↓
AddHandler cgi-script .cgi .pl ←コメント解除&変更(.cgiと.plを許可)
</IfModule>
AddDefaultCharset UTF-8
↓
#AddDefaultCharset UTF-8 ←コメントアウト(デフォルトの文字コードを指定しない)
mod_deflate(ファイル圧縮転送)設定
[root@centos ~]# vi /etc/httpd/conf.d/deflate.conf
↓下記を記入
<IfModule mod_deflate.c>
# Restrict compression to these MIME types
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/css
# Level of compression (Highest 9 - Lowest 1)
DeflateCompressionLevel 9
# Netscape 4.x has some problems.
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
</IfModule>
welcome.conf無効化
[root@centos ~]# mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.org
index.html作成
[root@centos ~]# echo '<h1>It works!</h1>' > /var/www/html/index.html
ドキュメントルートの所有権を変更
[root@centos ~]# chown -R user_name /var/www/html
シンボリックリンク作成
[root@centos ~]# ln -s /usr/bin/perl /usr/local/bin/perl
Apache起動
[root@centos ~]# systemctl start httpd
[root@centos ~]# systemctl enable httpd
[root@centos ~]# systemctl is-enabled httpd
enabled
ブラウザで確認 (http://ドメイン名/ にアクセス)
外部に公開する場合
プロトコル(TCP)ポート80番(HTTP)を開放。