通过Nginx基于路径的路由到同一服务器上的不同容器

时间:2020-05-12 10:01:07

标签: docker nginx reverse-proxy

我在端口上的服务器上运行着3个不同的docker容器-

  1. 容器1-本地主机:5000
  2. 容器2-本地主机:8000
  3. 容器3-本地主机:9000

我想配置服务器,以便每当请求在以下路径上命中时,都应将其重定向到相关容器-

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

我已经完成了将/ container1重定向到localhost:5000的操作。但是,它不提供容器1中托管的任何静态文件

我的nginx.conf文件-


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

关于如何为每个容器提供静态文件的任何建议?

当我在浏览器中打开localhost / container1时,当它应用于'localhost / container1 /'时,它正在'localhost /'路由上获取静态文件

对此将提供任何帮助。

0 个答案:

没有答案