Nginx 实现虚拟机

      Nginx 实现虚拟机

    可以实现在同一台服务运行多个网站,而且网站之间互相不干扰,同一个服务器可能有一个ip,网站需要使用80端口。网站的域名不同,区分不同的网站有三种方式:

    1.ip区分

    2.端口号区分

    3.域名区分

一、ip区分主机配置

          server { #一个Server就是一个虚拟主机
                          listen       80;
                         server_name  192.168.112.159;

                         #charset koi8-r;

                        #access_log  logs/host.access.log  main;

                        location / {
                                  root   html-159;
                                 index  index.html index.htm;
                      }
              }

         server { #一个Server就是一个虚拟主机
                          listen       80;
                         server_name  192.168.112.152;

                         #charset koi8-r;

                        #access_log  logs/host.access.log  main;

                        location / {
                                  root   html-152;
                                 index  index.html index.htm;
                      }
              }

二、基于端口的虚拟主机

          server {
               listen       81;
               server_name  192.168.25.141;

               #charset koi8-r;

               #access_log  logs/host.access.log  main;

              location / {
                 root   html-81;
                index  index.html index.htm;
            }     
       }
        server {
             listen       82;
            server_name  192.168.25.141;

            #charset koi8-r;

            #access_log  logs/host.access.log  main;

            location / {
               root   html-82;
               index  index.html index.htm;
            }
    }

三、基于域名的虚拟主机配置

      server {
             listen       80;
             server_name  域名1;

             #charset koi8-r;

             #access_log  logs/host.access.log  main;

           location / {
                root   html-www;
                index  index.html index.htm;
         }  
    }

      server {
             listen       80;
            server_name  域名2;

            #charset koi8-r;

            #access_log  logs/host.access.log  main;

           location / {
               root   html-hehe;
              index  index.html index.htm;
          }    
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值