Webサーバーの構築
Webサイトを公開するためのWebサーバーを構築します。
設定ファイルは各々の環境に合わせて適宜設定します。
Apache(httpd)のインストール
[root@centos ~] yum -y install httpd
Apacheの基本的な設定
Apacheの設定ファイルは /etc/httpd/conf/httpd.conf です。
以下、基本的なディレクティブの設定を行います。
[root@centos ~]# vi /etc/httpd/conf/httpd.conf ※apacheの設定ファイルをテキストエディタで開く - HTTPレスポンスヘッダのServerヘッダの情報を最小限にする - ServerTokens OS ↓ ServerTokens Prod - エラーページに表示されるメールアドレスを設定。エラーがあった際はここに設定したメールアドレスに通知がいく - ServerAdmin root@localhost ↓ ServerAdmin webmaster@linuxserver.jp - サーバーの名前を設定 - #ServerName www.example.com:80 ↓ ServerName linuxserver.jp:80 - DocumentRootを設定 - DocumentRoot "/var/www/html" ※Webサーバーで表示するHTMLやPHPなどのファイルを設置する場所だが、特に変更する場合がない場合はデフォルトでOK - DocumentRootを設定 - <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.2/mod/core.html#options # for more information. # Options Indexes FollowSymLinks ↓ Options ExecCGI FollowSymLinks Includes # # 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 ※ディレクトリごとにApacheの設定を変更できる「.htaccess」を使用できるようにする。 # # Controls who can get stuff from this server. # Order allow,deny Allow from all </Directory> - DirectoryIndex - DirectoryIndex index.html index.html.var ↓ DirectoryIndex index.html index.php index.cgi ※「http://www.example.com/」のようにアクセスした場合に表示されるファイルを設定する。この設定例の場合、index.html・index.php・index.cgiの内のいづれかがディレクトリ内にある場合、先に記述したファイル名から順に検索され表示される。 - AddDefaultCharset - AddDefaultCharset UTF-8 ↓ #AddDefaultCharset UTF-8 ※デフォルトで文字コードを指定しないようにする
ドキュメントルートの所有者を変更
[root@centos ~]# chown user1. /var/www/html/ ※ドキュメントルートの所有者を変更する。ここでは例としてuser1を所有者に設定
Apacheの起動
[root@centos ~]# /etc/rc.d/init.d/httpd start ※Apacheを起動 [root@centos ~]# chkconfig httpd on ※OS起動時にApacheが起動するように設定
ルーターの80番ポートを開放する。
最終更新 2009-03-07

この記事へのコメント
まだコメントは投稿されていません。