connect() failed (111: Connection refused) while connecting to upstream

问题背景:使用docker,部署nginx,配置子域名,映射不同web项目,比如a.baicu.com访问 /home/a,而b.baidu.com访问 /home/b 

# docker部署nginx报错

2024/06/12 09:44:34 [error] 22#22: *1 connect() failed (111: Connection refused) while connecting to upstream, client: xx.59.18.xx, server: console.xxx.top, request: "GET / HTTP/1.1", upstream: "http://xx.75.181.xx:8001/", host: "console.xxx.top"

先看nginx配置

server {
        listen  8001;
        server_name  localhost;
        location / {
            # root   html;
            root  /home/ruoyi/console;
            index  index.html;
            try_files $uri $uri/ /index.html;
        }
    }
    
    server {
        listen  80;
        # 你的域名
        server_name  a.baicu.com;

        location / {
            # 公网IP
            proxy_pass http://xx.x.xx.98:8001;
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }

问题一、

需要开启端口 8001的端口,包括防火墙和云服务器的8001端口

问题二、

因为使用的是docker部署,所以dockerfile文件也要映射端口

version: '3.1'

services:
  nginx:
    image: nginx
    restart: always
    container_name: nginx
    hostname: nginx
    ports:
      - 80:80
      - 443:443
      - 8001:8001
    environment:
      TZ: Asia/Shanghai
    volumes:
      - /data/nginx/conf:/etc/nginx
      - /data/nginx/logs:/var/log/nginx
      - /data/nginx/html:/usr/share/nginx/html
      - /home/ruoyi/console:/home/ruoyi/console/

 

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值