使用Nginx(dockerise)指向两个具有相同端口但不同位置指令的不同Docker服务

2fjabf4q  于 2023-10-17  发布在  Nginx
关注(0)|答案(1)|浏览(122)
upstream engine.app {
    server engine:8000;
}
server {
    listen 80;
    server_name engine.app;
    location / {
        proxy_pass http://engine.app;
        proxy_set_header Host "localhost";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
    }
}

upstream parser.app {
    server parser:8000;
}
server {
   listen 80;
   server_name parser.app;
   location /parser {
       proxy_pass http://parser.app;
       proxy_set_header Host "localhost";
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
       proxy_redirect off;
   }
}

给定此nginx配置
server_ip/engineserver_ip/engine/route1工作时,我无法在server_ip/parser上公开解析器服务。
我有两个Docker服务parser:8000engine:8000。最后,我想把解析器:8000服务公开到互联网上,就像对引擎一样。
请告知。
参考文献:

  1. Similar Case 1
wbgh16ku

wbgh16ku1#

upstream parser.app {
    server parser:8000;
}
upstream engine.app {
    server engine:8000;
}
server {
    listen 80;
    server_name engine;
     location / {
        proxy_pass http://engine.app/;
        proxy_set_header Host "localhost";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
    }
    location /parser/ {
        proxy_pass http://parser.app/;
        proxy_set_header Host "localhost";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_redirect off;
    }
}

在代理传递地址中添加尾随/起作用。(同时只保留一台服务器。)

大卫和汉斯的提示

相关问题