首页 > 后端开发 > php教程 > Nginx匹配ip

Nginx匹配ip

WBOY
发布: 2016-07-29 09:16:11
原创
1691 人浏览过

Nginx 匹配ip

定义反向代理

<code>upstream portal<span>.hongxue</span><span>.com</span> {
server <span>192.168</span><span>.0</span><span>.216</span>:<span>100</span> weight=<span>1</span><span>;</span>
}

upstream mobile<span>.hongxue</span><span>.com</span> {
server <span>192.168</span><span>.0</span><span>.216</span>:<span>200</span> weight=<span>1</span><span>;</span>
}

upstream console<span>.hongxue</span><span>.com</span> {
server <span>192.168</span><span>.0</span><span>.216</span>:<span>300</span> weight=<span>1</span><span>;</span>
}</code>
登录后复制

定义Server{}配置

<code>server {
listen <span>80</span>;
server_name www.hongxue.com;
charset utf8;

location / {
<span>if</span> ( <span>$remote_addr</span> = <span>"10.1.2.6"</span> )
    {
    proxy_pass http:<span>//console.hongxue.com;</span><span>break</span>;
    }
<span>if</span> ( <span>$remote_addr</span> = <span>"10.1.2.5"</span> )
    {
    proxy_pass http:<span>//portal.hongxue.com;</span><span>break</span>;
    }
<span>if</span> ( <span>$remote_addr</span> = <span>"10.1.2.7"</span> )
    {
    proxy_pass http:<span>//mobile.hongxue.com;</span><span>break</span>;
}
    proxy_pass http:<span>//192.168.0.223/;</span>
}
}</code>
登录后复制

版权声明:本文为博主原创文章,未经博主允许不得转载。

以上就介绍了Nginx匹配ip,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板