Nginx implementation of Virtual host

Source: Internet
Author: User

First, what is a virtual host?

A single httpserver can provide multiple HTTP services, which can be divided into the following virtual hosts depending on how they are accessed:

1. Port Virtual Host

2.IP Virtual Host

3. Domain Name Virtual host


Second, the implementation of the configuration

1. Port Virtual Host

   .......    http {     ....     server {        listen 8080;         #  here set the listener port of the virtual host         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 Virtual host (IP1,IP2 required on the server)

  .......    http {     ....     server {        listen IP1:80;         #  set the listener port of the virtual host here         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. Domain Name Virtual host

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



This article is from the "Lu2yu" blog, make sure to keep this source http://lu2yu.blog.51cto.com/10009517/1626497

Nginx implementation of Virtual host

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.