stack_pop
stack_pop

Reputation: 11

Nginx server returning 404 for static files when set as reverse proxy

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

Upvotes: 0

Views: 130

Answers (2)

Furkan
Furkan

Reputation: 171

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;
    }
}

Upvotes: 0

Giverseal
Giverseal

Reputation: 128

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

Upvotes: 0

Related Questions