您的位置:首页 > 运维架构 > Nginx

nginx配置虚拟主机

2014-12-31 11:31 363 查看
nginx设置虚拟主机很简单:
基于端口的虚拟主机:
server {
listen       81;
server_name  somename  alias  another.alias;
location / {
root   html/81;
index  index.html index.htm;
}
}
server {
listen       82;
server_name  somename  alias  another.alias;
location / {
root   html/82;
index  index.html index.htm;
}
}
[root@centos-server conf]# mkdir ../html/81
[root@centos-server conf]# mkdir ../html/82
[root@centos-server conf]# echo "<h1>81</h1>" > ../html/81/index.html
[root@centos-server conf]# echo "<h1>82</h1>" > ../html/82/index.html
[root@centos-server conf]# service nginx restart







基于IP:
server {
listen       192.168.150.137;
server_name  somename  alias  another.alias;
location / {
root   html/81;
index  index.html index.htm;
}
}
server {
listen       192.168.150.138;
server_name  somename  alias  another.alias;
location / {
root   html/82;
index  index.html index.htm;
}
}


[root@centos-server conf]# ifconfig eth6:0 192.168.150.137
[root@centos-server conf]# ifconfig eth6:1 192.168.150.138
[root@centos-server conf]# echo "<h1>192.168.150.137</h1>" > ../html/81/index.html
[root@centos-server conf]# echo "<h1>192.168.150.138</h1>" > ../html/82/index.html
[root@centos-server conf]# service nginx restart







基于域名:
server {
listen       80;
server_name  www.dragon.com;
location / {
root   html/81;
index  index.html index.htm;
}
}
server {
listen       80;
server_name  www.test.com;
location / {
root   html/82;
index  index.html index.htm;
}
}
[root@centos-server conf]# echo "<h1>www.test.com</h1>" > ../html/82/index.html
[root@centos-server conf]# echo "<h1>www.dragon.com</h1>" > ../html/81/index.html
[root@centos-server conf]# service nginx restart

我用window的浏览器访问,设置域名解析在"C:\Windows\System32\drivers\etc\hosts"添加
192.168.150.135 www.dragon.com
192.168.150.135 www.test.com






内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  虚拟主机 nginx