Apache2 インストール

Apache2インストール
[root@centos ~]# yum -y install httpd
httpd.conf編集
[root@centos ~]# vi /etc/httpd/conf/httpd.conf
ServerTokens OS
↓
ServerTokens Prod ←変更(サーバーの情報を隠す)

KeepAlive Off
↓
KeepAlive On ←変更(クライアントとの接続を保持する)

ServerAdmin root@localhost
↓
ServerAdmin postmaster@centos.orz ←変更(管理者のメールアドレスを記入)

#ServerName www.example.com:80
↓
ServerName www.centos.orz: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.2/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.
#
    Order allow,deny
    Allow from all

</Directory>

    UserDir disable
    ↓
    #UserDir disable ←コメントアウト(ユーザーディレクティブを許可)

    #UserDir public_html
    ↓
    UserDir public_html ←コメント解除(ユーザーのディレクトリをpublic_htmlとする)

↓下記をコメント解除
<Directory /home/*/public_html>
    #AllowOverride FileInfo AuthConfig Limit Indexes
    ↓
    AllowOverride All ←変更(.htaccess許可)

    #Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    ↓
    Options Includes ExecCGI FollowSymLinks ←変更(CGI,SSIを許可。ファイル一覧表示禁止)
    <Limit GET POST OPTIONS PROPFIND>
        Order allow,deny
        Allow from all
    </Limit>
    <LimitExcept GET POST OPTIONS PROPFIND>
        Order deny,allow
        Deny from all
    </LimitExcept>
</Directory>
↑ここまでコメント解除

DirectoryIndex index.html index.html.var
↓
DirectoryIndex index.html index.htm index.cgi ←変更(index.cgi許可)

ErrorLog logs/error_log
↓
ErrorLog /var/log/httpd/error_log ←変更(エラーログ)

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 ←変更(アクセスログ)

ServerSignature On
↓
ServerSignature Off ←変更(Apacheのバージョン情報を隠す)

<Directory "/var/www/icons">
    Options Indexes MultiViews
    ↓
    Options -Indexes MultiViews ←変更(ファイル一覧表示禁止)
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

AddLanguage ja .ja ←この行を最上位に移動

LanguagePriority ja ←jaを先頭に移動

AddDefaultCharset UTF-8
↓
#AddDefaultCharset UTF-8 ←コメントアウト(デフォルトの文字コードを設定しない)

#AddHandler cgi-script .cgi
↓
AddHandler cgi-script .cgi .pl ←コメント解除&変更(.cgi許可)
mod_deflate(ファイル圧縮転送)設定
[root@centos ~]# vi /etc/httpd/conf.d/deflate.conf
↓下記を記入
<Location />
  # Insert filter
  SetOutputFilter DEFLATE

  # 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 \bMSIE !no-gzip !gzip-only-text/html

  # NOTE: Due to a bug in mod_setenvif up to Apache 2.0.48
  # the above regex won't work. You can use the following
  # workaround to get the desired effect:
  BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

  # Don't compress images
  SetEnvIfNoCase Request_URI \
      \.(?:gif|jpe?g|png|ico|z|taz|t?gz|t?bz2?|zip|lzh|sit|rar|pdf|mp3|ogg|wma|rm|wmv|mov|mpe?g)$ \
      no-gzip dont-vary

  # Make sure proxies don't deliver the wrong content
  Header append Vary User-Agent env=!dont-vary
</Location>
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 ~]# /etc/rc.d/init.d/httpd start
[root@centos ~]# chkconfig httpd on
[root@centos ~]# chkconfig --list httpd
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
FTP用リンク作成
[root@centos ~]# ln -s /var/www/html /home/user_name/html
ブラウザで確認 (http://www.ドメイン名/ にアクセス)

外部に公開する場合
プロトコル(TCP)ポート80番(HTTP)を開放。
Home PageTop