Bad Gateway from Nginx to Docker Container [duplicate]

I have a PHP (Symfony) app which I created a Dockerfile from.

Dockerfile

FROM ubuntu:20.04

ENV PHP_VERSION=7.4 
    PHP_FPM_USER=www-data

# Install required system packages and dependencies
RUN apt-get update 
 && DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends 
      php-fpm php-cli php-gd php-pgsql php-xml zip unzip curl 
 && mkdir -p /run/php/ 
 && sed -i 's/^listen = .*/listen = 0.0.0.0:9000/' /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf 
 && rm -rf /var/lib/apt/lists/*

RUN curl -s https://getcomposer.org/installer | php
RUN alias composer='php composer.phar'

# Copy Symfony Files
COPY . /app
WORKDIR /app

ARG APP_ENV=prod
ARG APP_DEBUG=0

ENV APP_ENV $APP_ENV
ENV APP_DEBUG $APP_DEBUG

# Memory limit increase is required by the dev image
RUN php -d memory_limit=256M bin/console cache:clear
RUN php bin/console assets:install

CMD ["/usr/sbin/php-fpm7.4", "-F"]

EXPOSE 9000

In my Production environment I have a docker-compose to fire it up (among other services):

docker-compose.yml


services:
  database:
    image: postgres:11
    volumes:
      - ./database:/var/lib/postgresql/data
    ports:
      - 8089:5432
  frontend:
    image: frontend:latest
    ports:
      - 8090:80
  backend:
    image: backend:latest
    links:
      - database
    ports:
      - 8093:80
networks:
  default:

The production server is running an Nginx, with a config like this:

sites-available.conf

server {
    server_name myapp.com; # FRONTEND WORKS
    location / {
        proxy_pass http://127.0.0.1:8090;
    }

}
server {
    server_name backend.myapp.com; # BACKEND DOES NOT WORK
    location / {
        proxy_pass http://127.0.0.1:8093;
    }

}

The container seem to run properly

docker ps

CONTAINER ID        IMAGE                              COMMAND                  CREATED             STATUS              PORTS                            NAMES
00d5d599aa20        backend-app:latest   "docker-php-entrypoi…"   20 hours ago        Up 5 seconds        9000/tcp, 0.0.0.0:8093->80/tcp   backend-app_1
e94cefa71d71        postgres:11                        "docker-entrypoint.s…"   20 hours ago        Up 5 seconds        0.0.0.0:8089->5432/tcp           dpo-operations_database_1
9afb3e4b0c71        frontend:latest      "/docker-entrypoint.…"   20 hours ago        Up 5 seconds        0.0.0.0:8090->80/tcp             frontend_1

Last Message from my backend container:

backend-app_1  | [25-Nov-2020 11:23:19] NOTICE: fpm is running, pid 1
backend-app_1  | [25-Nov-2020 11:23:19] NOTICE: ready to handle connections

However when I query the backend, I get

502 Bad Gateway
from my Nginx.

Is there anything wrong with my setup?

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *