Question

'Bad Gateway' nginx com docker-compose

Posted March 10, 2021 467 views
NginxDocker

I’m new to docking on NGINX and I think I may have made some mistakes, but come on. I built my application and dockerized it normally and in the end on my own VPS I ran the ‘docker-compe up’ and got success, accessing my server’s IP on the port I mapped on nginx it works, however the problem is when I’m configuring in a DNS, follow my code to explain better:

docker-compose.yml

version: "3"

services:
  db:
    image: postgres
    restart: always
    ports:
      - "5432:5432"
    networks:
      - animes-lobby
    environment:
      POSTGRES_USER: 
      POSTGRES_DB: 
      POSTGRES_PASSWORD: 
  backend:
    build: ./backend
    command: >
      bash -c "yarn build
      && yarn typeorm migration:run
      && yarn start:prod"
    networks:
      - animes-lobby
    ports:
      - "4000:4000"
    volumes:
      - ./backend:/backend
      - ./backend/node_modules
    depends_on:
      - db
  frontend:
    build: ./frontend
    command: >
      bash -c "yarn build
      && yarn start"
    networks:
      - animes-lobby
    ports:
      - "3000:3000"
    volumes:
      - ./frontend:/frontend
    depends_on:
      - backend
networks:
  animes-lobby:
    driver: bridge

moment that I run the docker-compose up

CONTAINER ID   IMAGE                     COMMAND                  CREATED          STATUS          PORTS                              NAMES
9bb32ec92e61   animeslobbycom_frontend   "docker-entrypoint.s…"   30 seconds ago   Up 28 seconds   0.0.0.0:3000-3001->3000-3001/tcp   animeslobbycom_frontend_1
8b0f09b039e4   animeslobbycom_backend    "docker-entrypoint.s…"   36 seconds ago   Up 29 seconds   0.0.0.0:4000-4001->4000-4001/tcp   animeslobbycom_backend_1
ed14f72e9db8   postgres                  "docker-entrypoint.s…"   36 seconds ago   Up 36 seconds   0.0.0.0:5432->5432/tcp             animeslobbycom_db_1

as mentioned, now I can access it via IP: PORT and it works perfectly, but when I do my virtualhost configuration:

server {
        listen 80;

        server_name animeslobby.com www.animeslobby.com;

        location / {
                proxy_http_version 1.1;
                proxy_cache_bypass $http_upgrade;

                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $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_pass http://localhost:3000;
        }
}

I have as a Bad Gateway return in the domain response, someone who has been through this, can you help me?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi there,

I have just tested the website that you’ve shared and it seems to be loading as expected.

Would you mind sharing here with the community how you got this working?

Usually, my guess would be that the browser is trying to automatically redirect http to https and if you don’t have an SSL certificate installed the connection might time out.

Regards,
Bobby