#author("2018-08-23T09:12:24+09:00","","") #author("2018-09-13T14:41:21+09:00","","") [[CentOS7]] *Apacheインストール [#ka6ec38a] Webサーバーは''Chrome''等のWebブラウザからWebページをみれるようにするためのサーバー。 ここでは、Webサーバーソフトとしてもっとも使用されている''Apache''を使用してWebサーバーを構築し、ホームページスペース提供サービスを行っている一般的なWebサーバーと同様に以下のことができるようにする。 -''CGI''は任意のディレクトリで実行できるようにする -''SSI''は拡張子が''shtml''の場合のみ実行できるようにする -''.htaccess''を使用できるようにする -''PHP''を使用できるようにする **Apacheインストール [#e8c3adde] |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# yum -y install httpd php php-mbstring &color(lime){← httpd、php、php-mbstringインストール};| |[root@localhost ~]# vi /etc/httpd/conf/httpd.conf &color(lime){← Apache設定ファイル編集};| |#ServerName www.example.com:80 &br; &color(lime){↓}; &br; ServerName hoge.com:80 &color(lime){← サーバー名を指定}; &br; &br; <Directory "/var/www/html"> &br; &br; # &br; # Possible values for the Options directive are "None", "All", &br; # or any combination of: &br; # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews &br; # &br; # Note that "MultiViews" must be named *explicitly* --- "Options All" &br; # doesn't give it to you. &br; # &br; # The Options directive is both complicated and important. Please see &br; # http://httpd.apache.org/docs-2.0/mod/core.html#options &br; # for more information. &br; # &br; Options Indexes FollowSymLinks &br; &color(lime){↓}; &br; Options Includes ExecCGI FollowSymLinks &color(lime){← CGI,SSIの許可}; &br; &br; # &br; # AllowOverride controls what directives may be placed in .htaccess files. &br; # It can be "All", "None", or any combination of the keywords: &br; # Options FileInfo AuthConfig Limit &br; # &br; AllowOverride None &br; &color(lime){↓}; &br; AllowOverride All &color(lime){← .htaccessの許可}; &br; &br; # &br; # The following directives define some format nicknames for use with &br; # a CustomLog directive (see below). &br; # &br; LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined &br; ↓ &br; LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined &color(lime){← 長すぎるURI(414エラー)はログに記録しない}; &br; &br; # &br; # For a single logfile with access, agent, and referer information &br; # (Combined Logfile Format), use the following directive: &br; # &br; SetEnvIf Request_URI "default\.ida" no_log &color(lime){← 追加(wormからのアクセスをログに記録しない)}; &br; SetEnvIf Request_URI "cmd\.exe" no_log &color(lime){← 〃}; &br; SetEnvIf Request_URI "root\.exe" no_log &color(lime){← 〃}; &br; SetEnvIf Request_URI "Admin\.dll" no_log &color(lime){← 〃}; &br; SetEnvIf Request_URI "NULL\.IDA" no_log &color(lime){← 〃}; &br; SetEnvIf Remote_Addr 192.168.1 no_log &color(lime){← 追加(内部からのアクセスをログに記録しない)}; &br; SetEnvIf Remote_Addr 127.0.0.1 no_log &color(lime){← 追加(自ホストからのアクセスをログに記録しない)}; &br; CustomLog logs/access_log combined env=!no_log &color(lime){← 上記以外のアクセスをログに記録する}; &br; &br; AddDefaultCharset UTF-8 &br; &color(lime){↓}; &br; &color(lime){#};AddDefaultCharset UTF-8 &color(lime){← コメントアウト(文字化け対応)}; &br; &br; #AddHandler cgi-script .cgi &br; &color(lime){↓}; &br; AddHandler cgi-script .cgi .pl &color(lime){← CGIスクリプトに.plを追加}; &br; &br; &color(lime){以下を最終行に追加}; &br; TraceEnable off &color(lime){← Traceメソッドを無効化(クロスサイトトレーシング対策)};| |[root@localhost ~]# vi /etc/httpd/conf.d/autoindex.conf &color(lime){← autoindex設定ファイル編集};| |<Directory "/usr/share/httpd/icons"> &br; Options MultiViews &color(lime){← iconsディレクトリのファイル一覧を表示しないようにする}; &br; AllowOverride None &br; Require all granted &br; </Directory>| |[root@localhost ~]# rm -f /etc/httpd/conf.d/welcome.conf &color(lime){← テストページ削除};| **Perlコマンドへ/usr/local/bin/perlでもアクセスできるようにする [#b93ede48] |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# ln -s /usr/bin/perl /usr/local/bin/perl &color(lime){← /usr/local/bin/perlから/usr/bin/perlへリンクをはる};| |[root@localhost ~]# ll /var/www/ &color(lime){← ドキュメントルート所有者変更確認};| |合計 24 &br; drwxr-xr-x 2 root root 4096 10月 5 11:45 cgi-bin &br; drwxr-xr-x 3 root root 4096 10月 9 00:19 error &br; drwxr-xr-x 5 centos centos 4096 9月 27 17:43 html &br; drwxr-xr-x 3 root root 4096 9月 27 09:29 icons| **Apache起動 [#n02e4c89] |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# systemctl start httpd &color(lime){← Apache起動};| |[root@localhost ~]# systemctl enable httpd &color(lime){← Apache自動起動設定};| **TCP80番ポート開放 [#c799323a] ''【ルーター】'' ルーター側の設定で、''TCP80''番ポートへのアクセスをサーバーに転送するようにする。 ※ルーターの設定は各ルーターのマニュアルまたはメーカー別ルーターポート開放手順を参照 ''【ファイアウォール】※ファイアウォール導入している場合のみ'' サーバー側のファイアウォール設定で、''TCP80''番ポートへのアクセスを許可するようにする。 [[Portチェックテスト【外部からのPort開放確認】>http://www.cman.jp/network/support/port.html]]で「ホスト名(''FQDN'') または グローバルIPアドレス」にサーバー名(例:hoge.com)、「チェックポート番号」に''80''と入力、「ご注意・制約事項」を確認チェックして「Portチェック実行」ボタンを押下し、 -ホスト:''hoge.com'' -ポート:''80'' -にアクセスできました と表示されることを確認。 **外部からのWebサーバーアクセス確認 [#fa3c2079] 外部からWebサーバーにアクセスできるか確認する。 |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# echo test >> /var/www/html/index.html &color(lime){← テストページ作成};| [[Free Monitoring Test Tools>http://www.websitepulse.com/help/tools.php?tab=http]]の「Select Test Type」欄で「Website Test」を選択、「Enter Test Target」欄にドメイン名(例:http://hoge.com)を入力して「Perform Test」ボタンを押下する。 以下のような結果が表示されればOK ----- Website test results &br; &br; URL tested: http://hoge.com &br; Test performed from: New York, NY &br; Test performed at: 2017-02-18 05:38:24 (GMT +00:00) &br; Resolved As: XXX.XXX.XXX.XXX &br; Status: OK ← OKを確認 &br; Response Time: 1.021 sec &br; DNS: 0.360 sec &br; Connect: 0.192 sec &br; Redirect: 0.000 sec &br; First byte: 0.233 sec &br; Last byte: 0.237 sec &br; Size: 30325 bytes &br; ----- |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# rm -f /var/www/html/index.html &color(lime){← テストページ削除};| **Apache確認 [#cf1820f3] ***Webページ表示確認 [#c60d1136] |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# vi /var/www/html/index.html &color(lime){← テストページ作成};| |<html> &br; <head> &br; <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> &br; <title>テスト</title> &br; </head> &br; <body> &br; テスト &br; </body> &br; </html>| http://サーバー名/にアクセスしてテストページが表示されればOK ***CGI確認 [#t118f685] ''CGI''で簡単なテストページを表示してみる。 |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# vi /var/www/html/test.cgi &color(lime){← テスト用CGI作成};| |#!/usr/local/bin/perl &br; print "Content-type: text/html\n\n"; &br; print "<html>\n"; &br; print "<head>\n"; &br; print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n"; &br; print "<title>テスト</title>\n"; &br; print "</head>\n"; &br; print "<body>\n"; &br; print "CGIテスト\n"; &br; print "</body>\n"; &br; print "</html>\n";| |[root@localhost ~]# chmod 755 /var/www/html/test.cgi &color(lime){← テスト用CGIパーミッション変更};| http://サーバー名/test.cgiにアクセスして''CGI''テストページが表示されれば''OK'' ***SSI確認 [#da84b6da] SSIで現在日時を表示してみる。 |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# vi /var/www/html/test.shtml &color(lime){← SSIテスト用ページ作成};| |<html> &br; <head> &br; <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> &br; <title>テスト</title> &br; </head> &br; <body> &br; SSIテスト &br; <!--#config timefmt="%Y/%m/%d %H:%M:%S" --> &br; <!--#echo var="DATE_LOCAL" --> &br; </body> &br; </html>| http://サーバー名/test.shtmlにアクセスして現在日時を表示する''SSI''テストページが表示されれば''OK'' ***.htaccess確認 [#pcbd8588] ''.htaccess''で''DirectoryIndex''(ファイル名を省略した場合に表示されるページ)を''index.html''から''index.shtml''に変更してみる。 |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# vi /var/www/html/.htaccess &color(lime){← .htaccessファイル作成};| |DirectoryIndex index.shtml| |[root@localhost ~]# vi /var/www/html/index.shtml &color(lime){← .htaccessテスト用ページ作成};| |<html> &br; <head> &br; <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> &br; <title>テスト</title> &br; </head> &br; <body> &br; <p>.htaccessによるWebサーバー設定(例としてDirectoryIndex)の変更テスト</p> &br; このページのファイル名は<!--#echo var="DOCUMENT_NAME" --> &br; </body> &br; </html>| http://サーバー名/にアクセスして''index.shtml''が表示されれば''OK'' ***PHP確認 [#u5c0340b] ''PHP''で簡単なテストページを表示してみる。 |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# vi /var/www/html/test.php &color(lime){← PHPテスト用ページ作成}; &br; <?php &br; phpinfo(); &br; ?>| http://サーバー名/test.phpにアクセスして''phpinfo''ページが表示されれば''OK'' **Webサーバー確認後始末 [#c86dd9ba] 上記の確認で作成したテスト用ページ等を全て削除する。 |BGCOLOR(black):COLOR(white):|c |[root@localhost ~]# rm -f /var/www/html/* &color(lime){← 作成したテスト用ページを全て削除};| |[root@localhost ~]# rm -f /var/www/html/.htaccess &color(lime){← 作成した.htaccessを削除};|