2 years ago

#67231

test-img

mh f

`NGINX` reverse proxy does not work in `DOKCER` (502 bad gateway)

I have a VPS, my problem is that proxy_pass does not work, I get the 502 badgateway([error] 23#23: *1 connect() failed (111: Connection refused) while connecting to upstream,)

I saw similar questions but each case is different, please help me if you can.

The following is my configs:

NGINX (default.conf)

server {
  listen 80 default_server;
  server_name _;

  location /account {
    proxy_pass http://my_app_api:7000/account/;
  }

  location /info {
    return 200 "MHF";
    default_type text/plain;
  }
}

docker-compose.yml

version: "2.4"

networks:
  # internal:
  web:
    external:
      name: my-app-network

services:
  my_app_api:
    build: .
    container_name: my-app-container
    env_file: .env
    restart: always
    stop_grace_period: 2m
    networks:
      - web
    ports:
    - 7000:7000
    depends_on:
      - db
    environment:
      DB_HOST_LOCAL: $DB_HOST_LOCAL
      CHALLENGE_CODE_MIN: $CHALLENGE_CODE_MIN
      CHALLENGE_CODE_MAX: $CHALLENGE_CODE_MAX
    logging:
      driver: json-file
      options:
        max-size: '12m'
        max-file: '2'

  db:
    image: mongo:4.0
    container_name: db_mongo
    env_file: .env
    restart: always
    stop_grace_period: 2m
    networks:
      - web
    environment:
      MONGO_DB_URI_LOCAL: $MONGO_DB_URI_LOCAL
      MONGO_DB_NAME: $MONGO_DB_NAME
      ME_CONFIG_MONGO_DB_USERNAME: $ME_CONFIG_MONGO_DB_USERNAME
      ME_CONFIG_MONGO_DB_PASSWORD: $ME_CONFIG_MONGO_DB_PASSWORD
    volumes:
      - ./my-app-db:/data/db
    ports:
        - 27017:27017

  nginx:
    image: nginx:latest
    container_name: nginx-container
    restart: always
    networks:
      - web
    depends_on:
      - my_app_api
    ports:
      - 80:80
    volumes:
      - type: bind
        source: ./nginx/default.conf
        target: /etc/nginx/conf.d/default.conf
        read_only: true
    logging:
      driver: json-file
      options:
        max-size: '12m'
        max-file: '2'

Dockerfile

FROM node:latest

# Create app directory & cd /app
WORKDIR /app
EXPOSE 7000

# Install app dependencies
COPY package.json yarn.lock ./

COPY .env .

# Install dependency
RUN yarn

# Bundle app source
COPY . .

CMD ["yarn", "start:debug"]

docker

nginx

docker-compose

nginx-reverse-proxy

0 Answers

Your Answer

Accepted video resources