Virtual Host: will be a server virtual more than one host, each virtual host can be a stand-alone site, can have a separate domain name, with a complete Intemet server function. The virtual hosts on the same host are completely independent of each other.
Simply put, you have two completely independent web sites that can run on a single server using a virtual host.
With Apache-like, Nginx can also configure a variety of Virtual GUI machine: One is based on the IP virtual host, the second is based on the domain name of the virtual host, the third is based on the virtual host port.
Nginx.conf
HTTP {
...
... #server就是定义主机的
#server {
# listen 8000;
# Listen somename:8080;
# server_name somename alias Another.alias;
# Location/{
# root html;
# Index index.html index.htm;
# }
#}
}
This section is the example of defining a virtual host
Can be copied directly inside the change can be added
For ease of management, it is common to create a single file (vhost.conf) and then specify the HTTP in the Nginx configuration file
Steps:
First create a file that defines a virtual host
Vim/usr/local/nginx/conf/vhost.conf
server { #添加一个server
listen ; #监听80端口
server_name www.baidu.com; #域名
location/{ #指定位置
root html/baidu; #主页所在目录
index index.html index.htm #索引文件
}
}
server {
listen ;
server_name www.qq.com;
Location/{
root html/qq;
Index index.html index.htm;
}
}
Add two virtual host two domain name, one is www.baidu.com one is www.qq.com
Then you need to specify in the Nginx master configuration file
Vim/usr/local/nginx/conf/nginx.conf
Add a row inside HTTP {}
Include vhost.conf;
Be sure to add to HTTP {} and avoid adding to the outside or other definition areas inside
Restart Service
respectively in/usr/local/nginx/html/baidu and/USR/LOCAL/NGINX/HTML/QQ under the creation of two index.html files, respectively written in Baidu and QQ test
[Root@rh5-4 conf]# ELinks Http://www.qq.com--dump
Qq
[Root@rh5-4 conf]# elinkshttp://www.baidu.com--dump
Baidu
Configuration Complete!
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Servers/web/