Open picturesque-software opened 6 months ago
I have chosen other docker network to deploy it. I could show my method here:
As mentioned above, my frontend docker container can't connect websocket with the backend docker container but the http connection does well.
Instead, I used host network on the frontend and backend container. And then I used nginx to proxy the websocket and the frontend page. The nginx config is following:
# 非强制重定向https
server {
listen 443 ssl; #侦听443端口,用于SSL
server_name YOUR_SERVERNAME; # 自己的域名
ssl_certificate /etc/nginx/cert/XXX.pem;
ssl_certificate_key /etc/nginx/cert/XXX.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
location / {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_pass http://127.0.0.1:3000;
}
location /ws/ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_pass http://127.0.0.1:8000;
}
}
BUT I still think it is not elegant. I don't know why I could not access the bakend by websocket but I could access the backend by http when using the same host: http://backend:8000.
If someone could offer more info about deployment, I would pretty appreciate.
hi! I am trying to deploy this project in Ubuntu 22.04. Firstly, I used 'ws://localhost:8000' as origin docker-compose file. But the websocket not connected. I found that in container the localhost can't access server outside. Then I used ws://backend:8000, the server name to access. The http request by http://backend:8000/ worked BUT the websocket by ws://backend:8000 is not connected.
here is my docker-compose file:
My browser error:
It looks very strange.
Could you tell me how you deploy the project to connect websocket please? @pycui @y1guo @Shaunwei What is the correct ws address?
Any info is helpful! Thanks for any rely. Sincerely.