Nginx虚拟主机配置范例代码
发布时间:2014-08-14 编辑:jiaochengji.com
Nginx虚拟主机配置范例代码
两个虚拟主机,纯静态:
复制代码 代码如下:
http {
index index.html;
server {
server_name www.domain1.com;
access_log logs/domain1.access.log main;
root /var/www/domain1.com/htdocs;
}
server {
server_name www.domain2.com;
access_log logs/domain2.access.log main;
root /var/www/domain2.com/htdocs;
} }
index index.html;
server {
server_name www.domain1.com;
access_log logs/domain1.access.log main;
root /var/www/domain1.com/htdocs;
}
server {
server_name www.domain2.com;
access_log logs/domain2.access.log main;
root /var/www/domain2.com/htdocs;
} }
独立虚拟主机:
复制代码 代码如下:
http {
index index.html;
server {
listen 80 default;
server_name _;
access_log logs/default.access.log main;
server_name_in_redirect off;
root /var/www/default/htdocs;
} }
index index.html;
server {
listen 80 default;
server_name _;
access_log logs/default.access.log main;
server_name_in_redirect off;
root /var/www/default/htdocs;
} }
指定所有的二级域名:
复制代码 代码如下:
server {
# Replace this port with the right one for your requirements
listen 80 [default|default_server]; #could also be 1.2.3.4:80
# Multiple hostnames separated by spaces. Replace these as well.
server_name star.yourdomain.com *.yourdomain.com; # Alternately: _
root /PATH/TO/WEBROOT/$host;
error_page 404 errors/404.html;
access_log logs/star.yourdomain.com.access.log;
index index.php index.html index.htm;
# serve static files directly
location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
location ~ .php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
# By all means use a different server for the fcgi processes if you need to
fastcgi_pass 127.0.0.1:YOURFCGIPORTHERE;
}
location ~ /.ht {
deny all;
} }
# Replace this port with the right one for your requirements
listen 80 [default|default_server]; #could also be 1.2.3.4:80
# Multiple hostnames separated by spaces. Replace these as well.
server_name star.yourdomain.com *.yourdomain.com; # Alternately: _
root /PATH/TO/WEBROOT/$host;
error_page 404 errors/404.html;
access_log logs/star.yourdomain.com.access.log;
index index.php index.html index.htm;
# serve static files directly
location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
location ~ .php$ {
include fastcgi_params;
fastcgi_intercept_errors on;
# By all means use a different server for the fcgi processes if you need to
fastcgi_pass 127.0.0.1:YOURFCGIPORTHERE;
}
location ~ /.ht {
deny all;
} }
您可能感兴趣的文章:
上一篇:Nginx gzip配置参数说明
下一篇:nginx配置反向代理的简单示例
[关闭]