VirtualHostExampleJa
Contents |
[edit] 静的なファイルを扱う2つのバーチャルホスト設定
#!nginx
http {
: server {
: listen 80;
: server_name www.domain1.com;
: access_log logs/domain1.access.log main;
: location / {
: index index.html;
: root /var/www/domain1.com/htdocs;
: }
: }
: server {
: listen 80;
: server_name www.domain2.com;
: access_log logs/domain2.access.log main;
: location / {
: index index.html;
: root /var/www/domain2.com/htdocs;
: }
: }
}
[edit] 全てのバーチャルホストを受け付ける設定 (0.6.xより前のバージョン)
#!nginx
http {
: server {
: listen 80 default;
: server_name _ *;
: access_log logs/default.access.log main;
: location / {
: index index.html;
: root /var/www/default/htdocs;
: }
: }
}
[edit] 全てのバーチャルホストを受け付ける設定 (0.6.xバージョン)
#!nginx
http {
: server {
: listen 80 default;
: server_name _;
: access_log logs/default.access.log main;
: server_name_in_redirect off;
: location / {
: index index.html;
: root /var/www/default/htdocs;
: }
: }
}
[edit] ワイルドカードでサブドメインへのアクセスをまとめて受け付ける設定
このように設定すると、新しいサブドメインのDNSレコードがサーバへ向けられた場合でも自動的にアクセスを受け付けてくれます。FCGIの設定も含まれている点に注意してください。静的なファイルのみ扱いたい場合は、FCGIに関する設定を取り除いてデフォルトのドキュメントをindex.htmlに変更してください。ドメイン毎に新しいvhost.confを作るよりはこの設定一つで済ませる方が良いでしょう:
#!nginx
server {
: # Replace this port with the right one for your requirements
: listen 80; #could also be 1.2.3.4:80
: # Multiple hostnames seperated by spaces. Replace these as well.
: server_name star.yourdomain.com *.yourdomain.com www.*.yourdomain.com;
: #Alternately: _ *
: root /PATH/TO/WEBROOT/$host;
: error_page 404 http://yourdomain.com/errors/404.html;
: access_log logs/star.yourdomain.com.access.log;
: location / {
: root /PATH/TO/WEBROOT/$host/;
: index index.php;
: }
: # serve static files directly
: location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|html)$ {
: access_log off;
: expires 30d;
: }
: location ~ .php$ {
: # By all means use a different server for the fcgi processes if you need to
: fastcgi_pass 127.0.0.1:YOURFCGIPORTHERE;
: fastcgi_index index.php;
: fastcgi_param SCRIPT_FILENAME /PATH/TO/WEBROOT/$host/$fastcgi_script_name;
: fastcgi_param QUERY_STRING $query_string;
: fastcgi_param REQUEST_METHOD $request_method;
: fastcgi_param CONTENT_TYPE $content_type;
: fastcgi_param CONTENT_LENGTH $content_length;
: fastcgi_intercept_errors on;
: }
: location ~ /\.ht {
: deny all;
: }
: }










