【nginx】代理导致新消息一直未读且无法使用IM聊天

问答 明道云nginx私有化部署  收藏
3 / 129

我私有化部署,明道云在 192.168.1.10:8880

还有一台密码网关设备同时连接内外两个网口,内网网口 192.168.1.200 ** 外网网口 172.16.0.2**

nginx 服务部署在 192 网段另外一台服务器:192.168.1.20,监听 4455 端口

办公电脑都在 172.16.0.*/24 网段

因为 IT 部门限制,我要想访问我的明道云,需要通过 http://172.16.0.2:20003/mingdao(密码网关) 这个地址去访问,当我用办公电脑(172.16.0.124)通过浏览器访问 http://172.16.0.2:20003/mingdao 时,密码网关把请求转发到 nginx 服务器 192.168.1.20:4455 端口,然后通过这台 nginx 配置中 location /mingdao { porxy_pass 192.168.1.10:8880 } ,可以访问到我的明道云。

我目前遇到的问题是:
如果我把 docker-compose.yaml ENV_ADDRESS_MAIN:设置为我的访问地址 http://172.16.0.2:20003,我的 http 服务正常,但是 IM/通知消息无法使用,WebSocket 异常。 如果我把 `ENV_ADDRESS_MAIN:设置为 192.168.1.10:8880,那么我使用 192 网段的设备,可以正常通过 192.168.1.10:8880/mingdao 访问到明道云,IM 和消息也都是正常的。

我该怎么修改我的 nginx,下面是目前的配置

location /mingdao {
set $real_ip '';
        if ($http_x_real_ip) {
            set $real_ip $http_x_real_ip;
        }
        if ($http_x_real_ip = '') {
            set $real_ip $remote_addr;
        }
        proxy_set_header X-Real-IP $real_ip;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass http://192.168.1.10:8880;
    }

    # IM 需要
    location ~ /mingdao/mds2 {
        proxy_set_header Host $http_host;
        proxy_hide_header X-Powered-By;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://192.168.1.10:8880;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
    }