I'm seeing the following error message in nginx logs
[0m[0;33;1mnginx.1 | [0;31;1m2023/05/24 10:16:17 [error] 144#144: *76 connect() failed (111: Connection refused) while connecting to upstream, client: 172.90.174.63, server: api-staging, request: "GET /ws/notifications/?userid=user1 HTTP/1.1", upstream: "https://127.0.0.1:8000/ws/notifications/?userid=user1", host: "api-staging"
nginx conf
server {
server_name api-staging;
listen 443 ssl http2 ;
access_log /var/log/nginx/access.log vhost;
ssl_session_timeout 5m;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
ssl_certificate /etc/nginx/certs/api-staging.crt;
ssl_certificate_key /etc/nginx/certs/api-staging.key;
ssl_dhparam /etc/nginx/certs/api-staging.dhparam.pem;
ssl_stapling on;
ssl_stapling_verify on;
ssl_trusted_certificate /etc/nginx/certs/api-staging.chain.pem;
add_header Strict-Transport-Security "max-age=31536000" always;
location /ws/ {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
location /ws/notifications/ {
proxy_pass http://127.0.0.1:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
location / {
proxy_pass http://api-staging;
}
}
Its secure websocket service implemented via Daphne that is listening to 8000. The service is indeed running. But from Daphne logs, it looks like the request Nginx is trying to forward is not received at all.
wget https://api-staging/ws/notifications/?userid=user123455
--2023-05-25 05:18:27-- https://api-stagingi/ws/notifications/?userid=user123455
Resolving api-staging (api-staging)... 138.164.92.3, 188.114.97.3, 2a06:98c1:3121::3, ...
Connecting to api-staging (api-staging)|138.164.92.3|:443... connected.
HTTP request sent, awaiting response... 502 Bad Gateway
2023-05-25 05:18:27 ERROR 502: Bad Gateway.
I'am not sure what changes I need to do to nginx conf to fix this. Any help will be hugeee. thanks