欢迎使用CSDN-markdown编辑器

实现一台主机下面的多个站点对应于一个nginx服务器的配置过程:

   一.配置你的nginx的config文件
      1.在nginx的目录下面创建vhosts文件夹
      2.文件夹下面创建相关的yy.com.conf  oil.com.conf  bbk.com.conf配置文件  其中配置文件的内容如下:
 我的yy.com.conf的配置
    server {
        listen       80;
        #正则匹配 相关的域名yy.cim
        server_name  ~^yy.com$;
        location / {
            #指定域名对应的路径
            root   D:/PhpEnvironment/www/yy;
           #指定默认的访问文件
            index  index.html index.htm index.php;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


        location ~ \.php$ {
            #指定域名对应的路径
            root           D:/PhpEnvironment/www/yy/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }


    }
 我的oil.com.conf的配置


server {
        listen       80;
        server_name  ~^oil.com$;
        location / {
            root   D:/PhpEnvironment/www/oil/public/;
            index  index.html index.htm index.php;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


        location ~ \.php$ {
            root           D:/PhpEnvironment/www/oil/public/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }


    }
 我的bbk.com.conf的配置


    server {
        listen       80;
        server_name  ~^bbk.com$;
        location / {
            root   D:/PhpEnvironment/www/bbk/public/;
            index  index.html index.htm index.php;
        }


        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }


        location ~ \.php$ {
            root           D:/PhpEnvironment/www/bbk/public/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }


    }
  3. confin/nginx.config的配置

   worker_processes  1;
   events {
          worker_connections  1024;
             }




 http {


      include       mime.types;


      default_type  application/octet-stream;


      #access_log  logs/access.log  main;


      sendfile        on;


      keepalive_timeout  65;






    include  D:/PhpEnvironment/nginx-1.10.1/vhosts/oil.com.conf;


    include  D:/PhpEnvironment/nginx-1.10.1/vhosts/yy.com.conf;


    include  D:/PhpEnvironment/nginx-1.10.1/vhosts/bbk.com.conf;
   }
4.检测你的nginx是否配置正确
    nginx.exe -t

二.配置你的hosts文件

1.在windows下hosts的文件的路径是


  C:\Windows\System32\drivers\etc


我的配置如下:
127.0.0.1           oil.com


127.0.0.1           yy.com


127.0.0.1           bbk.com
2.刷新dns
cmd命令行下:
ipconfig /flushdns
3.重启nginx
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值