
TOP >> centos >> Apacheサーバー構築(RPM)
[root@centos ~]# yum -y install httpd ← httpdインストール [root@centos ~]# yum -y install php php-mbstring ← php、php-mbstringインストール
[root@centos ~]# vi /etc/httpd/conf/httpd.conf ← httpd設定ファイル編集 ServerTokens OS ↓ ServerTokens Prod ← エラーページ等でOS名を表示しないようにする ServerAdmin root@localhost ↓ ServerAdmin webmaster@centossrv.com ← エラーページ等に表示される管理者メールアドレスを指定 #ServerName www.example.com:80 ↓ ServerName centossrv.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.0/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の許可 # # The following directives define some format nicknames for use with # a CustomLog directive (see below). # LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined ↓ LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined ← 長すぎるURI(414エラー)はログに記録しない # # For a single logfile with access, agent, and referer information # (Combined Logfile Format), use the following directive: # SetEnvIf Request_URI "default\.ida" no_log ← 追加(wormからのアクセスをログに記録しない) SetEnvIf Request_URI "cmd\.exe" no_log ← 〃 SetEnvIf Request_URI "root\.exe" no_log ← 〃 SetEnvIf Request_URI "Admin\.dll" no_log ← 〃 SetEnvIf Request_URI "NULL\.IDA" no_log ← 〃 SetEnvIf Remote_Addr 192.168.1 no_log ← 追加(内部からのアクセスをログに記録しない) CustomLog logs/access_log combined env=!no_log ← 上記以外のアクセスをログに記録する ServerSignature On ↓ ServerSignature Off ← エラーページ等でApacheのバージョンを表示しないようにする AddDefaultCharset UTF-8 ↓ #AddDefaultCharset UTF-8 ← コメントアウト #AddHandler cgi-script .cgi ↓ AddHandler cgi-script .cgi .pl ← CGIスクリプトに.plを追加 <Directory "/var/www/icons"> Options Indexes MultiViews ↓ Options MultiViews ← iconsディレクトリのファイル一覧を表示しないようにする AllowOverride None Order allow,deny Allow from all </Directory> [root@centos ~]# rm -f /etc/httpd/conf.d/welcome.conf ← テストページ削除 [root@centos ~]# rm -f /var/www/error/noindex.html ← テストページ削除
[root@centos ~]# ln -s /usr/bin/perl /usr/local/bin/perl ← /usr/local/bin/perlから/usr/bin/perlへリンクをはる [root@centos ~]# whereis perl ← Perlのパスを確認 perl: /usr/bin/perl /usr/local/bin/perl /usr/share/man/man1/perl.1.gz ← Perlのパスに/usr/local/bin/perlが表示されることを確認
[root@centos ~]# chown centos. /var/www/html/ ← ドキュメントルート所有者変更 [root@centos ~]# ll /var/www/ ← ドキュメントルート所有者変更確認 合計 24 drwxr-xr-x 2 root root 4096 10月 5 11:45 cgi-bin drwxr-xr-x 3 root root 4096 10月 9 00:19 error drwxr-xr-x 5 centos centos 4096 9月 27 17:43 html drwxr-xr-x 3 root root 4096 9月 27 09:29 icons
[root@centos ~]# /etc/rc.d/init.d/httpd start ← httpd起動 httpd を起動中: [ OK ] [root@centos ~]# chkconfig httpd on ← httpd自動起動設定 [root@centos ~]# chkconfig --list httpd ← httpd自動起動設定確認 httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off ← ランレベル2~5のonを確認
(3)外部からのWebサーバーアクセス確認
外部からWebサーバーにアクセスできるか確認する。
[root@centos ~]# vi /var/www/html/index.html ← テストページ作成 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">※システムの文字コードがUTF-8の場合 <meta http-equiv="Content-Type" content="text/html; charset=euc-jp">※システムの文字コードがEUCの場合 <title>テスト</title> <body> テスト </body> </html>
(2)CGI確認
CGIで簡単なテストページを表示してみる。
[root@centos ~]# vi /var/www/html/test.cgi ← テスト用CGI作成 #!/usr/local/bin/perl print "Content-type: text/html\n\n"; print "<html>\n"; print "<head>\n"; print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n";※システムの文字コードがUTF-8の場合 print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=euc-jp\">\n";※システムの文字コードがEUCの場合 print "<title>テスト</title>\n"; print "</head>\n"; print "<body>\n"; print "CGIテスト\n"; print "</body>\n"; print "</html>\n"; [root@centos ~]# chmod 755 /var/www/html/test.cgi ← テスト用CGIパーミッション変更
(4).htaccess確認
[root@centos ~]# vi /var/www/html/.htaccess ← .htaccessファイル作成 DirectoryIndex index.shtml [root@centos ~]# vi /var/www/html/index.shtml ← .htaccessテスト用ページ作成 <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">※システムの文字コードがUTF-8の場合 <meta http-equiv="Content-Type" content="text/html; charset=euc-jp">※システムの文字コードがEUCの場合 <title>テスト</title> <body> <p>.htaccessによるWebサーバ設定(例としてDirectoryIndex)の変更テスト</p> このページのファイル名は<!--#echo var="DOCUMENT_NAME" --> </body> </html>
Webサーバー(Apache)はInternet Explorer等のブラウザから
Webページをみれるようにするためのサーバー。
ここでは、ホームページスペース提供サービスを行っている
一般的なWebサーバーと同様に以下のことができるようにする。
・CGIは任意のディレクトリで実行できるようにする
・SSIは拡張子がshtmlのもののみ実行できるようにする
・.htaccessを使用できるようにする
・PHPを使用できるようにする