首页 > 解决方案 > 通过 nginx 暴露多个 docker 服务

问题描述

我正在使用 nginx 为一个由 docker 容器生成的网站提供服务,该网站也位于 docker 容器中。这个设置工作得很好。

我现在想做的是从多个容器为多个网站提供服务。

我的(简化的)设置如下。

http {

upstream app_01 {
    server container_01:80;
}

upstream app_02 {
    server container_02:80;
}

server {
    listen 443 ssl;
    include common.conf;
    include /etc/nginx/ssl.conf;

    location / {
        proxy_pass         http://app_01;
        proxy_redirect     off;
        include common_location.conf;
    }

    location /alternative {
        proxy_pass         http://app_02;
        proxy_redirect off;
        include common_location.conf;
    }
}

}

common_location.conf包含:

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;
proxy_set_header    Host                $host;
proxy_set_header    X-Forwarded-Host    $server_name;
proxy_set_header    X-Forwarded-Port    $server_port;

我原来的网站仍然可以正常工作(container_01),我可以访问第二个网站(container_02);起始页面被部分加载。它似乎保留了upload/所有链接中的部分。

我的问题:我如何让它工作?

标签: nginx-reverse-proxynginx-location

解决方案


由于似乎没有人能够回答,我最终使用了 nginx 的替代品,它在十分钟内就可以工作。


推荐阅读