skip to Main Content

two docker containers are running two websites with apache as a server on port 60000 and 60002
nginx docker(created with nginx docker image) as a reverse proxy hosted on port 61001
the ip address is 10.0.2.15
when http://10.0.2.15:61001/app1 is called, it returns a blank website
after checking network, its returning 502 bad gateway

server {
    listen 80;
    server_name 10.0.2.15;

    location /app1/ {
        proxy_pass http://10.0.2.15:60000/;
        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;
    }

    location /app2/ {
        proxy_pass http://10.0.2.15:60002/;
        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;
    }
}

this is the default.conf file in the nginx docker container

ideally it should be going to http://10.0.2.15:61001/app1/static/ for all the content
and the react apps are all applications with routes as well
or is there any better way implementing this
enter image description here

2

Answers


  1. http {
    
    server {
    
        server_name 10.0.2.15;
        listen 80;
        listen [::]:80;
        
        location /app1 {
            set $url "http://10.0.2.15:60000"; # or try your lan ip
        }
        location /app2 {
            set $url "http://10.0.2.15:60002"; # or try your lan ip
        }
         }
    }
    

    you can try this

    Login or Signup to reply.
  2. You cannot listen on port 80 by establishing a connection through port 61001. You need to listen on port 61001

    You need to configure the nginx settings as follows:

    server {
        listen 61001;
        server_name 10.0.2.15;
    
        location /app1/ {
            proxy_pass http://10.0.2.15:60000/;
            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;
        }
    
        location /app2/ {
            proxy_pass http://10.0.2.15:60002/;
            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;
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search