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