nginx配置虚拟主机
2014-12-31 11:31
363 查看
nginx设置虚拟主机很简单:
基于端口的虚拟主机:
[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:
[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
基于域名:
[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
基于端口的虚拟主机:
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配置虚拟主机
- nginx关于配置多个虚拟主机和向后台转发的配置文件
- Nginx的虚拟主机配置
- Nginx配置之基于域名的虚拟主机
- Nginx的虚拟主机配置
- Nginx1.0.9配置虚拟主机
- nginx配置虚拟主机
- 【NGINX】虚拟主机配置示例
- Nginx虚拟主机配置教程
- 【Nginx】配置基于域名的虚拟主机
- Nginx下多虚拟主机的配置
- nginx配置虚拟主机
- Nginx 配置虚拟主机
- 生产环境下的nginx.conf配置文件(多虚拟主机) (转)
- NGINX:虚拟主机配置
- nginx配置虚拟主机,代理服务器
- Nginx 配置虚拟主机
- Nginx配置之基于域名的虚拟主机
- Nginx配置之基于域名的虚拟主机
- 生产环境下的nginx.conf配置文件(多虚拟主机) 推荐