首页 > Windows开发 > 详细

配置虚拟主机(windows环境下nginx+php)

时间:2014-02-15 01:21:24      阅读:470      评论:0      收藏:0      [点我收藏+]

需要给一个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配置

bubuko.com,布布扣

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

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

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

       第二步:内容如下图

bubuko.com,布布扣

以下是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文件bubuko.com,布布扣把域名绑定了,就可以啦

bubuko.com,布布扣

 

 

测试:http://b.comok

配置虚拟主机(windows环境下nginx+php)

原文:http://www.cnblogs.com/songqiaoli/p/3549233.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!