I am getting this error below from nginx
[error] 32#32: *4 upstream prematurely closed connection while reading response header from upstream, client: 172.21.0.1, server: , request: "GET / HTTP/1.1", upstream: "http://172.21.0.2:8844/", host: "localhost"
I have tried using the exact nginx config below as documented in wiki.polkadot.network/docs/maintain-wss#set-up-nginx-server
server {
listen 80 default_server;
root /var/www/html;
index index.html;
location / {
proxy_buffering off;
proxy_pass http://172.21.0.2:8844;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
listen [::]:443 ssl default_server ipv6only=on;
listen 443 ssl default_server;
ssl_certificate /etc/ssl/certs/nginx-selfsigned.crt;
ssl_certificate_key /etc/ssl/private/nginx-selfsigned.key;
ssl_session_cache shared:cache_nginx_SSL:1m;
ssl_session_timeout 1440m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers "ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS";
ssl_dhparam /etc/ssl/certs/dhparam.pem;
}
Keypoints
- 502 error occurs locally in a docker-compose environment but the WS & WSS connection still works on PolkadotJS
- 502 return code in a cloud environment fails because the health check on the LB is expecting a 200 HTTP code hence marks the Nginx proxy as unhealthy and doesnt route the traffic through
Please advice on what I could do to prevent this nginx error, I have tried every possible solution online. Ideally I would like a 200 HTTP return code when connecting to the Substrate Node's Websocket