首页 > 其他 > 详细

nginx配置虚拟主机

时间:2014-12-31 16:32:19      阅读:229      评论:0      收藏:0      [点我收藏+]

 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配置虚拟主机

原文:http://dragon123.blog.51cto.com/9152073/1598036

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!