首页 技术 正文
技术 2022年11月14日
0 收藏 480 点赞 2,397 浏览 1928 个字

关于nginx的多站设置,其实和apache很相似哒。

假设我们已经有两个域名,分别是:www.websuitA.com和www.websuitB.com。并且这两个域名已经映射给了IP为192.168.1.1的服务器。

1、为我们的站点创建配置文件

我是这么做的,在nginx的配置文件conf目录下创建一个专门存放VirtualHost的目录,命名为vhosts_conf,可以把虚拟目录的配置全部放在这里。在里面创建名为vhosts_modoupi_websuitA.conf的配置文件并打开,我们在这里做配置,往里面写:

server {

listen 80;               #监听的端口号

server_name websuitA.com;        #域名

#access_log logs/host.access.log main;

location / {

root X:/wnmp/www/websuitA;    #站点的路径

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/websuitA;

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的配置,同样的方法,做websuitB的配置,这里我命名为vhosts_modoupi_websuitB.conf

server {

     listen 80;               #监听的端口号

     server_name websuitB.com;        #域名

     #access_log logs/host.access.log main;

     location / {

        root X:/wnmp/www/websuitB;    #站点的路径

       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/websuitB;

        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;

     }

}

 

这样,两个站点的配置就OK了。 
2、在nginx的主配置文件里,包含这两个站点的配置文件。 
  我们打开conf目录下的nginx.conf文件,很容易做,只要在http{…}段输入以下代码: 

#包含所有的虚拟主机的配置文件

include X:/wnmp/nginx/conf/vhosts_conf/*.conf;

 

这样,nginx的多站点配置就做好了,怎么样打开浏览器测试一下吧~ 

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,494
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295