nginx下,一個server標籤就是一個虛擬主機。
nginx 配置虛擬主機的三種方法
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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.