Nginx, a server tag is a virtual host.
1, the domain-based virtual host, through the domain name to differentiate the virtual host-application: external website
2, Port-based virtual host, through the port to differentiate the virtual host-application: The company's internal Web site, external Web site management background
3, IP-based virtual host, almost no.
Configure virtual host steps based on domain name:
Need to establish the/data/www/data/bbs directory, the Windows Local hosts add virtual machine IP address corresponding domain name resolution, the corresponding domain name site directory under the new index.html file;
The nginx.conf configuration file adds the following code:
server {Listen 80; server_name www.yong.com; Index index.html; Root/data/www;} server {Listen 80; server_name bbs.yong.com; Index index.html; Root/data/bbs;}
Verify the results, use Curl test, or enter domain name access by the browser;
# curl-xlocalhost:80 Www.yong.comthis is Yong linux# curl-xlocalhost:80 bbs.yong.comthis are Yong BBS
Port-based virtual host configuration: use port to differentiate, browser use domain name or IP address: port number access;
server{Listen 8000; server_name www.yong.com; Root/data/www;} server{Listen 8001; server_name www.yong.com; Root/data/bbs;}
Verify the results, use Curl test, or enter domain name access by the browser;
# Curl Www.yong.com:8000this is Yong linux# Curl Www.yong.com:8001this is Yong BBS
IP address-based virtual host configuration: access through IP, need to configure multiple IP;
# ifconfig Eth0:1 192.168.22.21
server{Listen 192.168.20.20:80; server_name www.yong.com; Root/data/www;} server{Listen 192.168.20.21:80; server_name www.yong.com; Root/data/bbs;}
Verify the results, use Curl test, or enter domain name access by the browser;
# Curl 192.168.22.20this is Yong linux# Curl 192.168.22.21this is Yong BBS
This article is from the "Model Student's Learning blog" blog, please be sure to keep this source http://mofansheng.blog.51cto.com/8792265/1677849
Three ways to configure virtual host under Nginx