![]() |
この章を始める前に下記の設定が必要です 「logrotate インストール」 「MySQL インストール」
[root@ns1 ~]# cd /usr/ports/www/apache22 [root@ns1 apache22]# make BATCH=yes WITH_SUEXEC=yes SUEXEC_DOCROOT=/home WITHOUT_IPV6=yes install clean [root@ns1 apache22]# cd
[root@ns1 ~]# cp /usr/local/etc/apache22/httpd.conf /usr/local/etc/apache22/httpd.conf.org [root@ns1 ~]# vi /usr/local/etc/apache22/httpd.confServerAdmin you@example.com ↓ ServerAdmin postmaster@freebsd.orz ←変更 #ServerName www.example.com:80 ↓ ServerName www.freebsd.orz:80 ←コメント解除&変更 DocumentRoot "/usr/local/www/apache22/data" ↓ DocumentRoot "/home/hoge/public_html" ←変更 <Directory "/usr/local/www/apache22/data"> ↓ <Directory "/home/hoge/public_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 ←変更 # # 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 ←変更 # # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory> <IfModule dir_module> DirectoryIndex index.html index.htm index.php index.cgi ←変更(index.php index.cgiを追加) </IfModule> ErrorLog "/var/log/httpd-error.log" ↓ ErrorLog /var/log/httpd/hoge-error.log ←変更(エラーログ) <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/hoge-access.log combined env=!nolog ←変更 </IfModule> <IfModule mime_module> AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType application/x-httpd-php .php ←追加(.phpを使えるようにする) #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-vhosts.conf ↓ Include etc/apache22/extra/httpd-vhosts.conf ←コメント解除(バーチャルホスト設定) #Include etc/apache22/extra/httpd-default.conf #Include etc/apache22/extra/httpd-default.conf ←コメント解除(デフォルト設定)
※黄色い部分は環境に合わせて変更してください。
■httpd-languages.conf編集[root@ns1 ~]# vi /usr/local/etc/apache22/extra/httpd-languages.confAddLanguage ja .ja ←この行を最上位に移動 LanguagePriority ja ←jaを先頭に移動
[root@ns1 ~]# 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>
[root@ns1 ~]# rm /usr/local/etc/apache22/extra/httpd-vhosts.conf [root@ns1 ~]# vi /usr/local/etc/apache22/extra/httpd-vhosts.conf↓下記を記入 NameVirtualHost *:80 <VirtualHost *:80> ServerName any DocumentRoot /tmp </VirtualHost> <VirtualHost *:80> ServerName www.freebsd.orz ServerAlias freebsd.orz ServerAdmin postmaster@freebsd.orz DocumentRoot /home/hoge/public_html SuexecUserGroup hoge hoge ErrorLog /var/log/httpd/hoge-error.log CustomLog /var/log/httpd/hoge-access.log combined env=!nolog </VirtualHost>
※黄色い部分は環境に合わせて変更してください。
■httpd-default.conf編集[root@ns1 ~]# vi /usr/local/etc/apache22/extra/httpd-default.confServerTokens Full ↓ ServerTokens Prod ←変更(サーバーの情報を隠す) ServerSignature On ↓ ServerSignature Off ←変更(Apacheのバージョン情報を隠す)
[root@ns1 ~]# 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@ns1 ~]# cd /usr/ports/lang/php5 [root@ns1 php5]# make BATCH=yes WITH_APACHE=yes WITHOUT_IPV6=yes install clean
[root@ns1 php5]# cd /usr/ports/lang/php5-extensions [root@ns1 php5-extensions]# make BATCH=yes WITH_GD=yes WITH_MBSTRING=yes WITH_MYSQL=yes install clean
[root@ns1 ~]# cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini [root@ns1 ~]# chmod 644 /usr/local/etc/php.ini [root@ns1 ~]# vi /usr/local/etc/php.iniexpose_php = On ↓ expose_php = Off ←変更 max_execution_time = 30 ↓ max_execution_time = 300 ←変更(スクリプトの実行時間を300秒にする) ;default_charset = "iso-8859-1" ↓ default_charset = "UTF-8" ←コメント解除&変更 upload_max_filesize = 2M ↓ upload_max_filesize = 20M ←変更(アップロードの最大ファイルサイズを20MBにする) ;date.timezone = ↓ date.timezone = Asia/Tokyo ←コメント解除&変更(タイムゾーン指定) ;mbstring.language = Japanese ↓ mbstring.language = Japanese ←コメント解除 ;mbstring.internal_encoding = EUC-JP ↓ mbstring.internal_encoding = UTF-8 ←コメント解除&変更 ;mbstring.http_input = auto ↓ mbstring.http_input = auto ←コメント解除 ;mbstring.http_output = SJIS ↓ mbstring.http_output = pass ←コメント解除&変更 ;mbstring.encoding_translation = Off ↓ mbstring.encoding_translation = On ←コメント解除&変更 ;mbstring.detect_order = auto ↓ mbstring.detect_order = auto ←コメント解除 ;mbstring.substitute_character = none; ↓ mbstring.substitute_character = none; ←コメント解除
[root@ns1 ~]# cd /usr/ports/graphics/ImageMagick [root@ns1 ImageMagick]# make BATCH=yes install clean [root@ns1 ImageMagick]# cd
[root@ns1 ~]# mkdir /var/log/httpd [root@ns1 ~]# chown www: /var/log/httpd
[root@ns1 ~]# vi /etc/rc.conf[root@ns1 ~]# /usr/local/etc/rc.d/apache22 startapache22_enable="YES" ←追加(apache22起動)
[root@ns1 ~]# 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 }
外部に公開する場合 プロトコル(TCP)ポート80番(HTTP)を開放。
![]() |
![]() |
Last updated 2010-05-21 |