nginx反向代理本地 兩台web負載均衡 使用ip+端口代理


環境:

本地外網ip:123.58.251.166




1、配置index.html網頁

[root@host-10-1-1-161 conf.d]# cat /web/sing/index.html 
<h1>www.test1.com</h1>
[root@host-10-1-1-161 conf.d]# cat /root/html/index.html 
<h1>www.test2.com</h1>




2、配置conf.d目錄下配置文件

[root@host-10-1-1-161 conf.d]# pwd
/etc/nginx/conf.d
[root@host-10-1-1-161 conf.d]# ls
test1.conf  test2.conf  test3.conf
[root@host-10-1-1-161 conf.d]# cat test1.conf 
server {
listen 8083;
server_name 127.0.0.1:8083;
location / {
root /web/sing/;
index index.html index.htm;
}
}


[root@host-10-1-1-161 conf.d]# cat test2.conf 
server {
listen 8086;
server_name 127.0.0.1:8086;
location / {
root /root/html/;
index index.html index.htm;
}
}


[root@host-10-1-1-161 conf.d]# cat test3.conf 
upstream abc.com {
        server 127.0.0.1:8083 fail_timeout=20s;
        server 127.0.0.1:8086 fail_timeout=20s;
        #ip_hash;
       
}

server {

        listen       8085;
        server_name  127.0.0.1:8085;
        location / {
             #反向代理的地址
             proxy_pass http://abc.com;     
        }
}





[root@host-10-1-1-161 conf.d]# nginx -s reload



3、開始訪問     

注意:要從百度訪問必須注冊備案域名

[root@host-10-1-1-161 conf.d]# curl http://127.0.0.1:8085
<h1>www.test1.com</h1>
[root@host-10-1-1-161 conf.d]# curl http://127.0.0.1:8085
<h1>www.test2.com</h1>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM