Docker 容器内出现 NGINX 502 Bad Gateway 错误

Docker 容器内出现 NGINX 502 Bad Gateway 错误

直到今天,我的 Docker 容器或 NGINX 都没有出现任何问题,尽管我没有对配置文件、Docker 文件或项目中的任何其他文件进行任何更改,但却出现了随机意外的 502 Bad Gateway 错误。

502 错误来自/var/log/nginx/reverse-access.log

9.160.81.63 - - [25/Mar/2022:20:40:50 +0000] "GET /api/get_info HTTP/1.1" 502 559 "https://example.com:4000/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.82 Safari/537.36"

错误消息来自/var/log/nginx/reverse-error.log

[error] 26#26: *6 connect() failed (111: Connection refused) while connecting to upstream, client: 9.160.81.63, server: , request: "GET /api/get_info HTTP/1.1", upstream: "https://0.0.0.0:5000/api/get_info", host: "example.com:4000", referrer: "https://example.com:4000/"

/etc/nginx/conf.d/default.conf

server {
  listen 8765 ssl default_server;

  root /usr/share/nginx/html;
  index index.html index.html;

  ssl_certificate /etc/ssl/certs/example_project/cert.pem;
  ssl_certificate_key /etc/ssl/certs/example_project/key.pem;
  ssl_dhparam /etc/ssl/certs/example_project/dhparam.pem;

  ssl on;
  ssl_session_cache  builtin:1000  shared:SSL:10m;
  ssl_protocols  TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers HIGH:!aNULL:!eNULL:!EXPORT:!CAMELLIA:!DES:!MD5:!PSK:!RC4;
  ssl_prefer_server_ciphers on;
  ssl_session_timeout 60m;

  access_log /var/log/nginx/reverse-access.log;
  error_log /var/log/nginx/reverse-error.log;

  location / {
    try_files $uri /index.html =404;
  }

  location /api {

    proxy_pass          https://0.0.0.0:5000/api;

    proxy_redirect      default;
    proxy_set_header    Upgrade $http_upgrade;
    proxy_set_header    Connection "upgrade";
    proxy_set_header    Host $host:4000;
    proxy_set_header    X-Real-IP $remote_addr;
    proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Host $server_name;

  }
}

这一切都在node:15.7.0-alpine3.10同样使用的容器上运行nginx:stable-alpine。同样,我以前从未遇到过此错误,并且我没有对我的项目进行任何新的更改。为什么现在会出现此错误?我该如何修复它?

相关内容