小编haz*_*rot的帖子

WebSocketClient.js:16 WebSocket 连接到“ws://localhost:3000/ws”失败:React、Docker、NGINX

这是问题......当我在本地启动 React 应用程序时 npm start 。我没有连接失败。

如果我在 Docker 容器中启动 NGINX 和 React 服务器,我会不断得到

WebSocketClient.js:16 WebSocket 连接到“ws://localhost:3000/ws”失败:

默认配置文件

upstream client {
    server client:3000;
}

upstream api {
    server api:5000;
}   

server {
    listen 80;
    
    location / {
        proxy_pass http://client;
    }
    
    location /ws {
        proxy_pass http://client;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }
    
    location /api {
        rewrite /api/(.*) /$1 break;
        proxy_pass http://api;
    }
}
Run Code Online (Sandbox Code Playgroud)

nginx websocket docker reactjs ws

11
推荐指数
1
解决办法
3万
查看次数

标签 统计

docker ×1

nginx ×1

reactjs ×1

websocket ×1

ws ×1