首页 > 其他 > 详细

Nginx实现虚拟主机

时间:2015-03-31 01:09:42      阅读:299      评论:0      收藏:0      [点我收藏+]

一、何为虚拟主机?

     单个HTTPserver能提供多个http服务,根据访问的方式,可以分为以下几种虚拟主机:

                1.端口虚拟主机

                2.IP虚拟主机

                3.域名虚拟主机


二、配置实现

    1.端口虚拟主机

   .......
    http { 
    ....
    server {
        listen 8080;        # 这里设置虚拟主机的监听端口
        server_name virtual_host1;
        location / {
           root  /var/vhost/vhost1;      #vhost1的首页位置
           index index.html  index.htm;
        }

    }
        server {
        listen 80;          #这里设计虚拟主机的监听端口
        server_name virtual_host2;
        location / {
           root  /var/vhost/vhost2;         #vhost2的首页位置   
           index index.html  index.htm;
        }

    }
  }

    2.IP虚拟主机(IP1,IP2需要在服务器上)

  .......
    http { 
    ....
    server {
        listen IP1:80;        # 这里设置虚拟主机的监听端口
        server_name virtual_host1;
        location / {
           root  /var/vhost/vhost1;      #vhost1的首页位置
           index index.html  index.htm;
        }

    }
        server {
        listen IP2:80;          #这里设计虚拟主机的监听端口
        server_name virtual_host2;
        location / {
           root  /var/vhost/vhost2;         #vhost2的首页位置   
           index index.html  index.htm;
        }

    }
  }

    3.域名虚拟主机

.......
    http { 
    ....
    server {
        listen IP1:80;        
        server_name    #虚拟域名  
        location / {
           root  /var/vhost/vhost1;      #vhost1的首页位置
           index index.html  index.htm;
        }

    }
        server {
        listen IP2:80;         
        server_name     #虚拟域名 
        location / {
           root  /var/vhost/vhost2;         #vhost2的首页位置   
           index index.html  index.htm;
        }

    }
  }



本文出自 “Lu2Yu” 博客,请务必保留此出处http://lu2yu.blog.51cto.com/10009517/1626497

Nginx实现虚拟主机

原文:http://lu2yu.blog.51cto.com/10009517/1626497

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