nginx reverse proxy in docker getting 502 connection refused

Published

I’m trying to configure a reverse proxy to run strapi in nginx running in docker but I keep getting 502 bad gateway. Everything I look up seems to point to this being the correct way to do it but doesn’t work. The log tells me

[error] 32#32: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 10.0.0.10, server: _, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:1337/", host: "10.0.0.4"

Here’s the default.conf file that I’m copying in on container creation based on strapi’s reverse proxy documentation.

  server 127.0.0.1:1337;
}
server {
    listen 80;
    listen [::]:80;
    server_name _;
    location / {
        proxy_pass http://strapi;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header Host $http_host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
        proxy_pass_request_headers on;
    }
}

Here is dcoker-compose.yml too

version: '3.3'

services:
  nginx-proxy:
    image: public.ecr.aws/nginx/nginx:latest
    depends_on:
      - strapi
    ports:
      - '80:80'
    volumes:
      - ./default.conf:/etc/nginx/conf.d/default.conf

  strapi:
    image: public.ecr.aws/knowre/strapi:3.1.4-node12
    container_name:  strapi
    volumes:
      - ./app:/srv/app
    expose:
      - '1337'
    ports:
      - '1337:1337'

Source: Docker Questions

Published
Categorised as docker, nginx, nginx-reverse-proxy, strapi Tagged , , ,

Answers

Leave a Reply

Still Have Questions?


Our dedicated development team is here for you!

We can help you find answers to your question for as low as 5$.

Contact Us
faq