首页 > 代码库 > nginx配置虚拟主机
nginx配置虚拟主机
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配置虚拟主机