CentOS7

Apacheインストール

WebサーバーはChrome等のWebブラウザからWebページをみれるようにするためのサーバー。

ここでは、Webサーバーソフトとしてもっとも使用されているApacheを使用してWebサーバーを構築し、ホームページスペース提供サービスを行っている一般的なWebサーバーと同様に以下のことができるようにする。

Apacheインストール

[root@localhost ~]# yum -y install httpd php php-mbstring ← httpd、php、php-mbstringインストール
[root@localhost ~]# vi /etc/httpd/conf/httpd.conf ← Apache設定ファイル編集
#ServerName www.example.com:80

ServerName hoge.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 ← 追加(内部からのアクセスをログに記録しない)
SetEnvIf Remote_Addr 127.0.0.1 no_log ← 追加(自ホストからのアクセスをログに記録しない)
CustomLog logs/access_log combined env=!no_log ← 上記以外のアクセスをログに記録する

AddDefaultCharset UTF-8

#AddDefaultCharset UTF-8 ← コメントアウト(文字化け対応)

#AddHandler cgi-script .cgi

AddHandler cgi-script .cgi .pl ← CGIスクリプトに.plを追加

以下を最終行に追加
TraceEnable off ← Traceメソッドを無効化(クロスサイトトレーシング対策)
[root@localhost ~]# vi /etc/httpd/conf.d/autoindex.conf ← autoindex設定ファイル編集
<Directory "/usr/share/httpd/icons">
Options MultiViews ← iconsディレクトリのファイル一覧を表示しないようにする
AllowOverride None
Require all granted
</Directory>
[root@localhost ~]# rm -f /etc/httpd/conf.d/welcome.conf ← テストページ削除

Perlコマンドへ/usr/local/bin/perlでもアクセスできるようにする

[root@localhost ~]# ln -s /usr/bin/perl /usr/local/bin/perl ← /usr/local/bin/perlから/usr/bin/perlへリンクをはる
[root@localhost ~]# 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

Apache起動

[root@localhost ~]# systemctl start httpd ← Apache起動
[root@localhost ~]# systemctl enable httpd ← Apache自動起動設定

TCP80番ポート開放

【ルーター】

ルーター側の設定で、TCP80番ポートへのアクセスをサーバーに転送するようにする。

※ルーターの設定は各ルーターのマニュアルまたはメーカー別ルーターポート開放手順を参照

【ファイアウォール】※ファイアウォール導入している場合のみ

サーバー側のファイアウォール設定で、TCP80番ポートへのアクセスを許可するようにする。

Portチェックテスト【外部からのPort開放確認】で「ホスト名(FQDN) または グローバルIPアドレス」にサーバー名(例:hoge.com)、「チェックポート番号」に80と入力、「ご注意・制約事項」を確認チェックして「Portチェック実行」ボタンを押下し、

と表示されることを確認。

外部からのWebサーバーアクセス確認

外部からWebサーバーにアクセスできるか確認する。

[root@localhost ~]# echo test >> /var/www/html/index.html ← テストページ作成

Free Monitoring Test Toolsの「Select Test Type」欄で「Website Test」を選択、「Enter Test Target」欄にドメイン名(例:http://hoge.com)を入力して「Perform Test」ボタンを押下する。

以下のような結果が表示されればOK


Website test results

URL tested: http://hoge.com
Test performed from: New York, NY
Test performed at: 2017-02-18 05:38:24 (GMT +00:00)
Resolved As: XXX.XXX.XXX.XXX
Status: OK ← OKを確認
Response Time: 1.021 sec
DNS: 0.360 sec
Connect: 0.192 sec
Redirect: 0.000 sec
First byte: 0.233 sec
Last byte: 0.237 sec
Size: 30325 bytes


[root@localhost ~]# rm -f /var/www/html/index.html ← テストページ削除

Apache確認

Webページ表示確認

[root@localhost ~]# vi /var/www/html/index.html ← テストページ作成
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>テスト</title>
</head>
<body>
テスト
</body>
</html>

http://サーバー名/にアクセスしてテストページが表示されればOK

CGI確認

CGIで簡単なテストページを表示してみる。

[root@localhost ~]# 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";
print "<title>テスト</title>\n";
print "</head>\n";
print "<body>\n";
print "CGIテスト\n";
print "</body>\n";
print "</html>\n";
[root@localhost ~]# chmod 755 /var/www/html/test.cgi ← テスト用CGIパーミッション変更

http://サーバー名/test.cgiにアクセスしてCGIテストページが表示されればOK

SSI確認

SSIで現在日時を表示してみる。

[root@localhost ~]# vi /var/www/html/test.shtml ← SSIテスト用ページ作成
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>テスト</title>
</head>
<body>
SSIテスト
<!--#config timefmt="%Y/%m/%d %H:%M:%S" -->
<!--#echo var="DATE_LOCAL" -->
</body>
</html>

http://サーバー名/test.shtmlにアクセスして現在日時を表示するSSIテストページが表示されればOK

.htaccess確認

.htaccessDirectoryIndex(ファイル名を省略した場合に表示されるページ)をindex.htmlからindex.shtmlに変更してみる。

[root@localhost ~]# vi /var/www/html/.htaccess ← .htaccessファイル作成
DirectoryIndex index.shtml
[root@localhost ~]# vi /var/www/html/index.shtml ← .htaccessテスト用ページ作成
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>テスト</title>
</head>
<body>
<p>.htaccessによるWebサーバー設定(例としてDirectoryIndex)の変更テスト</p>
このページのファイル名は<!--#echo var="DOCUMENT_NAME" -->
</body>
</html>

http://サーバー名/にアクセスしてindex.shtmlが表示されればOK

PHP確認

PHPで簡単なテストページを表示してみる。

[root@localhost ~]# vi /var/www/html/test.php ← PHPテスト用ページ作成
<?php
phpinfo();
?>

http://サーバー名/test.phpにアクセスしてphpinfoページが表示されればOK

Webサーバー確認後始末

上記の確認で作成したテスト用ページ等を全て削除する。

[root@localhost ~]# rm -f /var/www/html/* ← 作成したテスト用ページを全て削除
[root@localhost ~]# rm -f /var/www/html/.htaccess ← 作成した.htaccessを削除

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2018-09-13 (木) 14:41:22