Path-based routing to different containers on the same server through Nginx

Viewed 2580

I have 3 different docker containers running on my server on ports -

  1. Container 1 - localhost:5000
  2. Container 2 - localhost:8000
  3. Container 3 - localhost:9000

I want to configure my server so that whenever a request hits on the below paths, it should get redirected to the relevant container -

  1. localhost/container1 -> localhost:5000
  2. localhost/container2 -> localhost:8000
  3. localhost/container3 -> localhost:9000

I have accomplished redirecting /container1 to localhost:5000. However, it's not serving any static files hosted in Container 1

My nginx.conf file -


#user  nobody;
worker_processes  1;

http {

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location /container1/ {
            proxy_pass http://127.0.0.1:5000;
        }

        #error_page  404              /404.html;

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

Any suggestions on how static files can be served for each container?

When I'm opening localhost/container1 in the browser then it's fetching the static files on 'localhost/' route when it should go for 'localhost/container1/'

Any help on this would be highly appreciated.

0 Answers
Related