Score:1

NGINX 502 Bad Gateway error inside Docker container

mx flag

I haven't had any issues with my Docker container or NGINX until today where I am getting a random unexpected 502 Bad Gateway error even though I have made no changes to my configuration files, Docker files, or any other file in my project.

The 502 error from /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"

The error message from /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;

  }
}

This is all running on a node:15.7.0-alpine3.10 container which is also using nginx:stable-alpine. Again, I've never faced this error before and I've committed zero new changes to my project. Why is this error occurring now and how do I fix it?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.