nginx多站点配置实例讲解
时间:2014-07-04 01:39 来源:linux.it.net.cn 作者:IT网
nginx多站点配置实例讲解
假设有两个域名,分别是:www.web01.com和www.web02.com,均解析到了192.168.1.1这个IP上。
1、创建站点配置文件
在nginx的配置文件conf目录下创建一个专门存放VirtualHost的目录,命名为vhosts_conf,可以把虚拟目录的配置全部放在这里。
在里面创建名为vhosts_modoupi_web01.conf的配置文件并写入内容:
复制代码代码示例:
server {
listen 80; #监听的端口号
server_name web01.com; #域名
#access_log logs/host.access.log main;
location / {
root X:/wnmp/www/web01; #站点的路径
index default.php index.php index.html index.htm;
#站点的rewrite在这里写
rewrite ^/(\w+)\.html$ /$1.php;
rewrite ^/(\w+)/(\w+)$ /$1/$2.php;
}
#错误页的配置
error_page 404 /error.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root X:/wnmp/www/web01;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
完成了站点A的配置,然后做web02的配置,如下:
复制代码代码示例:
server {
listen 80; #监听的端口号
server_name web02.com; #域名
#access_log logs/host.access.log main;
location / {
root X:/wnmp/www/web02; #站点的路径
index default.php index.php index.html index.htm;
#站点的rewrite在这里写
rewrite ^/(\w+)\.html$ /$1.php;
rewrite ^/(\w+)/(\w+)$ /$1/$2.php;
}
#错误页的配置
error_page 404 /error.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root X:/wnmp/www/web02;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
2、在nginx的主配置文件里,包含这两个站点的配置文件。
打开conf目录下的nginx.conf文件,在http{...}段输入:
复制代码代码示例:
#虚拟主机配置文件
include X:/wnmp/nginx/conf/vhosts_conf/*.conf;
(责任编辑:IT)
nginx多站点配置实例讲解 假设有两个域名,分别是:www.web01.com和www.web02.com,均解析到了192.168.1.1这个IP上。 1、创建站点配置文件
在nginx的配置文件conf目录下创建一个专门存放VirtualHost的目录,命名为vhosts_conf,可以把虚拟目录的配置全部放在这里。
复制代码代码示例:
server { #access_log logs/host.access.log main;
location / {
#站点的rewrite在这里写
#错误页的配置
error_page 500 502 503 504 /50x.html;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ /\.ht {
完成了站点A的配置,然后做web02的配置,如下:
复制代码代码示例:
server { #access_log logs/host.access.log main;
location / {
#站点的rewrite在这里写
#错误页的配置
location = /50x.html {
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ /\.ht {
2、在nginx的主配置文件里,包含这两个站点的配置文件。
复制代码代码示例:
#虚拟主机配置文件
(责任编辑:IT)include X:/wnmp/nginx/conf/vhosts_conf/*.conf; |