nginxでバーチャルホスト設定
前回nginxとFastCGIいれたけどバーチャルホストの設定もしたかったので設定した。
前回の記事:CentOS6.4にnginxとFastCGI入れる - わーくあうと!
設定ファイルを作る
vhost.confというファイルを作って
vi /etc/nginx/conf.d/vhosts.conf
中身はこんな感じにした
# バーチャルホスト用の設定.
# 基本的には /var/www/nginx/vhosts/ の下にホスト名のディレクトリ作るだけでOK.
server {
listen 8080;
server_name ~^(.*)?;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
# ↓ホントはホスト毎にアクセスログ分けたかったが $host が効かないようなので諦める。
# mainのログフォーマットに $http_host を付けたからgrepすれば見れるし。
#access_log /var/www/nginx/vhosts/$host/logs/access_log main;
root /var/www/nginx/vhosts/$host/html;
location / {
index index.html index.htm index.php;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
#root /var/www/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /var/www/nginx/vhosts/$host$fastcgi_script_name;
include fastcgi_params;
}
}
これであとは /var/www/nginx/vhosts/ の下にホスト名のディレクトリ作っていけばバーチャルホスト増やせる。
例)/var/www/nginx/vhost/hoge.domain.com
うん、シンプル。