关于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的多站点配置就做好了,怎么样打开浏览器测试一下吧~ 

nginx 多站点配置方法的更多相关文章

  1. nginx 多站点配置方法集合(转)

    关于nginx的多站设置,其实和apache很相似,假设我们已经有两个域名,分别是:www.websuitA.com和www.websuitB.com.并且这两个域名已经映射给了IP为192.168. ...

  2. nginx高性能WEB服务器系列之五--实战项目线上nginx多站点配置

    nginx系列友情链接:nginx高性能WEB服务器系列之一简介及安装https://www.cnblogs.com/maxtgood/p/9597596.htmlnginx高性能WEB服务器系列之二 ...

  3. WAMPServer多站点配置方法

    WAMPServer多站点配置方法:1.在C:\wamp\www 新建文件夹test01,在里面新建index.php,内容为 "Hello Test01". 2.C:\wamp\ ...

  4. php ci nginx 伪静态rewrite配置方法

    php ci nginx 伪静态rewrite配置方法 location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=/$ ...

  5. 通过浏览器查看nginx服务器状态配置方法

    通过浏览器查看nginx服务器状态配置方法 投稿:junjie 字体:[增加 减小] 类型:转载 这篇文章主要介绍了通过浏览器查看nginx服务器状态配置方法,本文讲解开启nginx-status的配 ...

  6. 二、Nginx多站点配置(参考宝塔的)分析

    一.基于宝塔配置文件分析(站的配置文件) 新增的站点配置即添加server并包含在nginx内 查找文件: 文件内容: 二.伪静态 伪静态是一种可以把文件后缀改成任何可能的一种方法,如果我想把php文 ...

  7. Ubuntu系统下lnmp环境搭建和Nginx多站点配置

    最近需要使用Ubuntu作为服务器搭建Lnmp环境,顺便将操作过程写下来,与大家分享.如有不足之处,欢迎大家提出不同意见.(本文默认读者已经熟悉相关linux命令的使用,比如创建文件和文件夹,编辑文件 ...

  8. Wampserver 2.5 多站点配置方法

    写在开头:本文适用于wampserver2.5版本,和wamp的老版本配置有语法上的区别,笔者正是因为被老版本的配置办法给整迷糊了所以才总结了一篇针对2.5版本的配置方法,如果您还停留在1.x或着已经 ...

  9. 一、Nginx多站点配置

    一.下载 目录文件: 二.运行方式 (1)直接双击nginx.exe,双击后一个黑色的弹窗一闪而过 (2)打开cmd命令窗口,切换到nginx解压目录下,输入命令 nginx.exe 或者 start ...

随机推荐

  1. C#隐式类型

    隐式类型 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sys ...

  2. 通用的 makefile 小工具分享 - Easymake 使用说明

    Easymake 使用说明 介绍 Easymake 是一个在linux系统中 C/C++ 开发的通用 makefile.在一个简单的 C/C++ 程序中使用 easymake,你甚至可以不写一行 ma ...

  3. case when then 与 count联合使用

    我们都知道SQL中适用case when then来转化数据库中的信息 比如  select (case sex when 0 then '男' else '女' end) AS sex  from ...

  4. "只能在执行Render()的过程中调用RegisterForEventValidation" 解决方案

    开发中遇到令人蛋疼的问题: 只能在执行Render()的过程中调用RegisterForEventValidation 当出现的异常的提示: 异常详细信息: System.InvalidOperati ...

  5. CSS3 动画效果合集

    @charset "UTF-8"; /*! * animate.css -http://daneden.me/animate * Version - 3.5.1 * License ...

  6. ADO.NET连接数据库的两种方式

    //实现了IDisposable接口的类,用using括起来 //插入数据 string connString = "Data Source=(local);Initial Catalog= ...

  7. 理解C#中的“静态”

    一.静态成员 1.通过static关键字修饰,是属于类,实例成员属于对象,在这个类第一次加载的时候,这个类下面的所有静态成员会被加载. 2.静态成员只被创建一次,所以静态成员只有一份,实例成员有多少个 ...

  8. C#微信公众号开发 -- (四)获取API调用所需的全局唯一票据access_token

    access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token.开发者需要进行妥善保存.access_token的存储至少要保留512个字符空间.access_to ...

  9. .NET 设计模式之单例模式(一)

    1.简单解释:在创建对象时,无论创建多少次,在堆空间上只会申请一次内存空间. 2.例子(1): public class Singleton{ private static Singleton _si ...

  10. c#保存textbox中的字符串到txt文件中

    /********************** 保存接收按钮 *****************************/ private void SavetxData_Click(object s ...