nginx下,一个server标签就是一个虚拟主机。
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;
}
验证结果,使用curl测试,或者浏览器输入域名访问
# curl -xlocalhost:80 www.yong.com
this is yong linux
# curl -xlocalhost:80 bbs.yong.com
this is yong bbs
2、基于端口的虚拟主机配置:
server
{
listen 8000;
server_name www.yong.com;
root /data/www;
}
server
{
listen 8001;
server_name www.yong.com;
root /data/bbs;
}
验证结果,使用curl测试,或者浏览器输入域名访问
# curl www.yong.com:8000
this is yong linux
# curl www.yong.com:8001
this is yong bbs
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;
}
验证结果,使用curl测试,或者浏览器输入域名访问
# curl 192.168.22.20
this is yong linux
# curl 192.168.22.21
this is yong bbs
本文出自“模范生的学习博客”博客,请务必保留此出处http://mofansheng.blog.51cto.com/8792265/1677849