nginx 在多重虛擬主機設定的方式如下:
listen 80 後若多加 default_server 為若沒有 match server_name 的預設虛擬主機, 另外都可以自定 error_log 與 access_log 的 log file.
abc.com
代碼: 選擇全部
server {
listen 80 default_server;
server_name abc.com;
error_log /var/log/nginx/abc.com-error.log warn;
access_log /var/log/nginx/abc.com-access.log combined;
root /var/www/abc.com;
index index.html index.htm;
#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 /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
def.com
代碼: 選擇全部
server {
listen 80;
server_name www.def.com def.com;
error_log /var/log/nginx/def.com-error.log warn;
access_log /var/log/nginx/def.com-access.log combined;
root /var/www/def.com;
index index.html index.htm;
#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 /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
#root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}
多多留言, 整理文章, 把經驗累積下來.....