I am trying to make websocket requests to go through two nginx proxies. It is to do SSR(server side rendering)
My stack is like: External World <-> nginx <-> rendora(SSR) <-> nginx <-> daphne <-> django
When I was doing External World <-> nginx <-> daphne <-> django
Websocket connections were established very well. But when I implemented rendora(SSR) and added another proxy to nginx, it does not work. Websocket connection fails while handshakes. I guess "Upgrade" requests fail somewhere in my nginx servers. My nginx conf is like below:
server {
listen 8000;
location / {
include proxy_params;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_pass http://unix:/home/ubuntu/myproject/myproject.sock;
}
}
server {
server_name mydomain;
charset utf-8;
location /static {
alias /home/ubuntu/myproject/apps/web-build/static;
}
location / {
include proxy_params;
proxy_pass http://127.0.0.1:3001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
listen 443 ssl; # managed by Certbot
...
}
So the location / port 443 sends all requests from external world to 127.0.0.1:3001 where rendora(SSR server) is listening to. And the SSR server (rendora) forwards them to 127.0.0.1:8000 where nginx proxy to connect to daphne unix socket.
SSR itself works well except the websocket requests. But I have no idea why websocket upgrade is not done when requests have to go through two nginx proxies.