Apache2 インストール


この章を始める前に下記の設定が必要です
「ログローテーション logrotate インストール」
pkgtools.conf編集
[root@freebsd ~]# vi /usr/local/etc/pkgtools.conf
  MAKE_ARGS = {
	'www/apache22' => 'WITH_SUEXEC=yes SUEXEC_DOCROOT=/home', ←追加
  }
Apache2インストール
[root@freebsd ~]# cd /usr/ports/www/apache22
[root@freebsd apache22]# make BATCH=yes WITH_SUEXEC=yes SUEXEC_DOCROOT=/home WITHOUT_IPV6=yes install clean
[root@freebsd apache22]# cd
http.conf編集
[root@freebsd ~]# vi /usr/local/etc/apache22/httpd.conf
ServerAdmin you@example.com
↓
ServerAdmin postmaster@freebsd.orz ←変更(管理者のメールアドレスを記入)

#ServerName www.example.com:80
↓
ServerName www.freebsd.orz:80 ←コメント解除&変更(サーバー名を記入)


<Directory "/usr/local/www/apache22/data">
    #
    # 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>

<IfModule dir_module>
    DirectoryIndex index.html
    ↓
    DirectoryIndex index.html index.htm index.cgi ←変更(index.htm index.cgiを許可)
</IfModule>

<IfModule log_config_module>
    CustomLog "/var/log/httpd-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>

#Include etc/apache22/extra/httpd-languages.conf
↓
Include etc/apache22/extra/httpd-languages.conf ←コメント解除(言語設定)

#Include etc/apache22/extra/httpd-userdir.conf
↓
Include etc/apache22/extra/httpd-userdir.conf ←コメント解除(ユーザーディレクティブ設定)

#Include etc/apache22/extra/httpd-default.conf
↓
Include etc/apache22/extra/httpd-default.conf ←コメント解除(デフォルト設定)
httpd-languages.conf編集
[root@freebsd ~]# vi /usr/local/etc/apache22/extra/httpd-languages.conf
AddLanguage ja .ja ←この行を最上位に移動

LanguagePriority ja ←jaを先頭に移動
httpd-userdir.conf編集
[root@freebsd ~]# vi /usr/local/etc/apache22/extra/httpd-userdir.conf
<Directory "/home/*/public_html">
    AllowOverride FileInfo AuthConfig Limit Indexes
    ↓
    AllowOverride All ←変更(.htaccessを許可)

    Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
    ↓
    Options Includes ExecCGI FollowSymLinks ←変更(CGI,SSIを許可。ファイル一覧表示禁止)
</Directory>
httpd-default.conf編集
[root@freebsd ~]# vi /usr/local/etc/apache22/extra/httpd-default.conf
ServerTokens Full
↓
ServerTokens Prod ←変更(サーバーの情報を隠す)

ServerSignature On
↓
ServerSignature Off ←変更(Apacheのバージョン情報を隠す)
mod_deflate設定
[root@freebsd ~]# vi /usr/local/etc/apache22/Includes/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>
ドキュメントルートの所有権を変更
[root@freebsd ~]# chown -R user_name /usr/local/www/apache22/data
logディレクトリ作成
[root@freebsd ~]# mkdir /var/log/httpd
[root@freebsd ~]# chown www: /var/log/httpd
Apache2起動
[root@freebsd ~]# vi /etc/rc.conf
apache22_enable="YES" ←追加(apache22起動)
[root@freebsd ~]# /usr/local/etc/rc.d/apache22 start Syntax OK Starting apache22.
ヒント
/usr/local/etc/rc.d/apache22: WARNING: failed to start apache22 このエラーはサーバーのホスト名とhttpd.confのServerNameで指定したホスト名が一致しない場合に出ます。
FTP用リンク作成
[root@freebsd ~]# ln -s /usr/local/www/apache22/data /home/user_name/data
ログローテーション
[root@freebsd ~]# vi /usr/local/etc/logrotate.d/apache22
↓下記を記入
/var/log/httpd/*log {
	daily
	rotate 4
	create
	nocompress
	missingok
	sharedscripts
	postrotate
		/usr/local/sbin/apachectl -k graceful
	endscript
}
ブラウザで確認 (http://www.ドメイン名/ にアクセス)

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