我在 nginx 日志中看到以下错误消息
[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 配置
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;
}
}
它是通过 Daphne 实现的安全 websocket 服务,监听 8000。该服务确实在运行。但从 Daphne 日志来看,Nginx 尝试转发的请求似乎根本没有收到。
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.
我不确定需要对 nginx conf 进行哪些更改才能解决这个问题。任何帮助都将非常有帮助。谢谢