WWWサーバーの構築
このページではWWWサーバー「Apache」の構築方法を紹介します。
じんたろうの場合は2つサイトがありますのでバーチャルホストで対応してます。
ユーザーごとに「/home/testuser/public_html」というディレクトリを作りドキュメントはそこに保存してます。
ログは「/home/testuser/httpd_logs」というディレクトリを作りそこに保存してます。
よって1ユーザーに1ホストという設定です。
Apacheのインストール
[root@jintaro ~]# yum -y install httpd
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
(中略)
Running Transaction
Installing: httpd ######################### [1/1]
Installed: httpd.i386 0:2.2.2-1.2
Complete!
[root@jintaro ~]# yum -y install php php-mbstring
Loading "installonlyn" plugin
Setting up Install Process
Setting up repositories
(中略)
Running Transaction
Installing: php ######################### [1/3]
Installing: php-mbstring ######################### [2/3]
Installing: php-pear ######################### [3/3]
Installed: php.i386 0:5.1.6-1.2 php-mbstring.i386 0:5.1.6-1.2
Dependency Installed: php-pear.noarch 1:1.4.9-1.2
Complete! |
httpdをインストール
phpとphp-mbstring
をインストール
|
Apacheの設定
[root@jintaro ~]# vi /etc/httpd/conf/httpd.conf
(中略)
AddDefaultCharset UTF-8
↓
#AddDefaultCharset UTF-8
(中略)
#AddHandler cgi-script .cgi
↓
AddHandler cgi-script .cgi .pl
(中略)
---最終行に追加 ここから---
NameVirtualHost *:80
<VirtualHost *:80>
ServerAdmin hoge@hoge.com
DocumentRoot /home/testuser/public_html
ServerName jintaro.com
ServerAlias jintaro.com *.jintaro.com
DirectoryIndex index.shtml index.php index.cgi index.html
<Directory /home/testuser/public_html>
Options FollowSymLinks ExecCGI Includes
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
ErrorLog /home/testuser/httpd_logs/error.log
SetEnvIf Remote_Addr 192.168. nolog
CustomLog /home/testuser/httpd_logs/access.log combined env=!nolog
</VirtualHost>
<VirtualHost *:80>
ServerAdmin hoge@hoge.com
DocumentRoot /home/testuser2/public_html
ServerName test.com
ServerAlias test.com *.test.com
DirectoryIndex index.shtml index.php index.cgi index.html
<Directory /home/testuser2/public_html>
Options FollowSymLinks ExecCGI Includes
AllowOverride AuthConfig
Order allow,deny
Allow from all
</Directory>
ErrorLog /home/testuser2/httpd_logs/error.log
SetEnvIf Remote_Addr 192.168. nolog
CustomLog /home/testuser2/httpd_logs/access.log combined env=!nolog
</VirtualHost>
---最終行に追加 ここまで---
[root@jintaro ~]# su - testuser
[testuser@jintaro ~]$ mkdir public_html
[testuser@jintaro ~]$ mkdir httpd_logs
[testuser@jintaro ~]$ exit
[root@jintaro ~]# su - testuser2
[testuser2@jintaro ~]$ mkdir public_html
[testuser2@jintaro ~]$ mkdir httpd_logs
[testuser2@jintaro ~]$ exit
[root@jintaro ~]# service httpd start
httpd を起動中: [ OK ]
[root@jintaro ~]# chkconfig httpd on
[root@jintaro ~]# chkconfig --list httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
|
Apacheの設定ファイルを開く
#でコメントアウト
変更(.cgiと.plでCGIが実行される)
1つ目のホスト
サーバー管理者
ドキュメントのルート
サーバーのドメイン名
ドメイン別名
indexファイルの種類
CGI,SSIを許可
htaccessのユーザー認証許可
エラーログを記録
ローカルからのアクセスを記録しない
アクセスログ
2つ目のホスト
rootからtestuserになる
ディレクトリpublic_htmlを作成
ディレクトリhttpd_logsを作成
rootに戻る
rootからtestuser2になる
ディレクトリpublic_htmlを作成
ディレクトリhttpd_logsを作成
rootに戻る
httpd(Apache)を起動
httpd自動起動on
httpd自動起動確認
2〜5でon
|
これで設定は終わりです。
ためしにDocumentRoot (この場合/home/testuser/public_html)にindex.html等を置いてクライアントからアクセスしてみましょう。
WAN側からアクセスする場合はルータの80番ポートをオープンします。
(注) 見れないときはtesuserディレクトリのパーミッションを確認しましょう。 当方の環境ではuseradd testuserでユーザーを追加したときにtestuserのパーミッションが700になってて見れませんでしたので755に変更しました。
|