My first upstream on Nginx works but the second doesnt

16 Views Asked by At

This is my Nginx Conf file when i access the nextjs upstream it works but the registrations it give 502 badgateway .Take note these are two totally diffrent but connected to the same docker nertwork


events {
    worker_connections 1024;  # Adjust as needed
}

http {`your text`
    # HTTP server settings

    # Define upstream block for the nextjs microservice
    upstream nextjs {
        server nextjs:3000; # Replace with the IP address and port of the nextjs service
    }

    # Define upstream block for the registrationsapp microservice
    upstream registrationsapp {
        server registrationsapp:9000; # Use the desired IP address and port for registrationsapp service
    }

    # Main server block to handle incoming requests
    server {
        listen 80;
        server_name my server_ip; 

         resolver 127.0.0.11; # Use Docker's internal DNS resolver
         
        location / {
            # Route requests to the nextjs service
            proxy_pass http://nextjs;
            proxy_set_header Host $host;
        }

        # Add any other API routes and their corresponding services here
        location /registrations {
            # Route requests to the registrationsapp service
            proxy_pass http://registrationsapp;
            proxy_set_header Host $host;
        }
    }
}

This my Nginx YML file

version: '3'

services:
  main_nginx:
    container_name: main_nginx
    image: nginx:alpine
    volumes:
      - ./main_nginx/nginx.conf:/etc/nginx/nginx.conf
    ports:
      - "80:80"
    networks:
      - internal_docker_network

networks:
  internal_docker_network:
    external: true

This the section my registrationsapp microservices YML file

 # Application Service for Teacher Registration
  registrationsapp:
    container_name: registrationsapp
    build:
      context: ./php
      dockerfile: Dockerfile
    volumes:
      - ./src:/var/www
    ports:
      - "9000:9000"
    working_dir: /var/www
    networks:
      - internal_docker_network
    restart: always

# Define the networks
networks:
 internal_docker_network:
    external: true

I expected since the nextjs can run then registrationsapp will also do the same but its giving 502 badgate way

0

There are 0 best solutions below