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>

 

转载于:https://www.cnblogs.com/effortsing/p/10012410.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值