首頁  >  文章  >  後端開發  >  Nginx匹配ip

Nginx匹配ip

WBOY
WBOY原創
2016-07-29 09:16:111652瀏覽

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教學有興趣的朋友有幫助。

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn