需要给一个ip绑定不同域名,例如有两个项目/www//www2/

需要http://a.com时访问的是www 项目

http://b.com访问的是www2项目

 

那么需要在nginx/conf下的nginx.conf文件里(一下是我的配置文件内容)

#user   nobody;

worker_processes  1;

 

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

 

pid        logs/nginx.pid;

 

 

events {

    worker_connections  1024;

}

 

 

http {

    include       mime.types;

    default_type  application/octet-stream;

 

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

 

    access_log  logs/access.log  main;

 

    sendfile        on;

    #tcp_nopush     on;

 

    #keepalive_timeout  0;

    keepalive_timeout  65;

 

    #gzip  on;

 

    server {

        listen       80;

        server_name  testngnix.com;

 

        #charset koi8-r;

 

        access_log  logs/host.access.log  main;

 

        location / {

            root   D:/dept/nginxmysqlphp/www;

            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   html;

        }

 

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80

        #

        #location ~ \.php$ {

        #    proxy_pass   http://127.0.0.1;

        #}

 

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

        #

        location ~ \.php$ {

            root           D:/dept/nginxmysqlphp/www;

            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;

        #}

 

      

      

        

    }

 

 

    # another virtual host using mix of IP-, name-, and port-based configuration

    #

 

 

    # HTTPS server

    #

    #server {

    #    listen       443;

    #    server_name  localhost;

 

    #    ssl                  on;

    #    ssl_certificate      cert.pem;

    #    ssl_certificate_key  cert.key;

 

    #    ssl_session_timeout  5m;

 

    #    ssl_protocols  SSLv2 SSLv3 TLSv1;

    #    ssl_ciphers  ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

    #    ssl_prefer_server_ciphers   on;

 

    #    location / {

    #        root   html;

    #        index  index.html index.htm;

    #    }

    #}

    include D:/dept/nginxmysqlphp/nginx/conf/vhost/*.conf;

}

注释:红色字体部分就是关键,将虚拟域名配置引入进来

include D:/dept/nginxmysqlphp/nginx/conf/vhost/*.conf;这句话,需要在nginx/conf下创建一个文件夹,里面放的都是虚拟ip配置

打开vohost文件夹,新建文件(以域名为名字.conf)结尾

例如:b.com 指向127.0.0.1,读取www2项目

      第一步:nginx/conf文件下,新建a.conf文件

       第二步:内容如下图

以下是b.conf的代码,可以自己拷贝然后将红框内的内容,按照自己的修改

 

server

        {

                listen       80;

                server_name  dali.com;

                index index.php index.html index.htm default.html default.htm default.php;

                root  D:/dept/nginxmysqlphp/www2;

           location ~ \.php$ {

            root           D:/dept/nginxmysqlphp/www2;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            include        fastcgi_params;

         }

        }

 

这样配置就可以啦。

最后。记得打开你本地的hosts文件把域名绑定了,就可以啦

测试:http://b.comok

配置虚拟主机(windows环境下nginx+php)的更多相关文章

  1. 搭建windows环境下(nginx+mysql+php)开发环境

    搭建windows环境下(nginx+mysql+php)开发环境   1. 所需准备应用程序包        1.1 nginx 程序包nginx-1.0.4.zip或其他版本(下载地址: http ...

  2. Windows环境下Nginx配置本地虚拟域名

    进入conf文件夹,新建servers文件夹: 将内部的server配置段提取单独放在一个文件里,存到了conf/servers下,以方便配置多个虚拟主机. 并在nginx.conf里http配置段内 ...

  3. windows 环境下nginx + tomcat群 + redis 实现session共享

    nginx作为负载均衡根据定义将不同的用户请求分发到不同的服务器,同时也解决了因单点部署服务器故障导致的整个应用不能访问的问题 在加入nginx之后,如果多个服务器中的一个或多个(不是全部)发生故障, ...

  4. windows环境下nginx的启动、停止

    Windows下Nginx的启动.停止等命令 在Windows下使用Nginx,我们需要掌握一些基本的操作命令,比如:启动.停止Nginx服务,重新载入Nginx等,下面我就进行一些简单的介绍.1.启 ...

  5. windows环境下 nginx+iis 反向代理解决跨域问题

    项目基本完成,是时候花点时间整理一下最近的姿势了 1 什么是跨域? 网上对于跨域的概念会有大篇幅的文章去解释,似乎有点玄乎,初学者很容易对这个概念产生恐惧,跨域其实很简单,其实只要知道一点,无法跨域访 ...

  6. 在windows环境下 nginx + .net core 3.1 实现反向代理和负载均衡

    一.创建.net core web 应用 1.首先打开vs2019创建好.net core web应用,简单的注入IConfiguration 便于打印端口号展示效果. 1 private reado ...

  7. windows环境下nginx服务器的安装与配置

    转载至:http://www.cnblogs.com/hxxy2003/archive/2012/09/20/2695254.html nginx服务器是一个高性能的HTTP和反向代理服务器,它以稳定 ...

  8. windows环境下Nginx部署及Https设置

    一.Nginx安装部署及常用命令. 1.1.其实Nginx是免安装的.直接在官网下载zip包,解压即可,下载地址:http://nginx.org/en/download.html,因为我这边的开发服 ...

  9. Nginx安装及配置虚拟主机

    nginx安装部分 依赖环境 yum -y install gcc zlib openssl-devel zlib-devel 1. 下载好下面两个包:nginx-1.8.1.tar.gz pcre- ...

随机推荐

  1. CSS控制之IE常见BUG及解决方案

    常见bug 解决方案 盒模型bug 使用严格doctype声明 双倍margin bug _display:inline; 不认识a:link 不加:link 3像素margin bug 规范浮动与清 ...

  2. 封装 INI 文件读写函数

    delphi读写ini文件实例 //--两个过程,主要实现:窗体关闭的时候,文件保存界面信息:窗体创建的时候,程序读取文件文件保存的信息. //--首先要uses IniFiles(单元) //--窗 ...

  3. endnote X7 加入文献

    endnote可以管理文献,并且在word中方便的添加参考文献. 1.加入文献: 2.导入以后可以创建自己的group,然后把导入的参考文献拖到group里,这样方便在插入参考文献的时候用group名 ...

  4. iOS oc和swift中协议的使用

    创建一个空的工程 在工程中我们新建一个类 继承与NSObject 定义一个协议‘ @protocol UpdateAlertDelegate <NSObject> //这里的红色字体就是我 ...

  5. HTML 样式- CSS

    如何使用CSS CSS 是在 HTML 4 开始使用的,是为了更好的渲染HTML元素而引入的. CSS 可以通过以下方式添加到HTML中: 内联样式- 在HTML元素中使用"style&qu ...

  6. 关于oracle导出时的query用法

    QUERY参数后面跟的是where条件,值得注意的是,整个where子句需要使用""括起来,where子句的写法和SELECT中相同: 如果是UNIX平台所有"和'都需 ...

  7. VisualGDB Makefiles

    以下内容是VisualGDB官网对VisualGDB编译时获取相关编译信息的说明: When you create a new project using VisualGDB, it will gen ...

  8. Js让光标停在输入框input框最后面

    var val = $(this) val();   1.$(this). focus(); 2.$(this).val(""); 3.$(this).val(val);   1. ...

  9. 005.数组、for、foreach

    1.方法的传输传递 值参数:传递的是副本 引用参数:自身 保留自定义的方法中对值的改变 形参影响实参ref:对应的形参和实参都用ref修饰 输出参数:实参不用赋值,但是自定义方法内必须对此参数赋值!! ...

  10. 2017-01-27-hibernate环境搭建

    Hibernate的环境搭建(uid方式): 1:导入包 2:创建实体对象 3:hibernate的映射配置文件 4:hibernate的核心配置文件 5:创建测试类实现表的创建 2:创建实体对象-U ...