Nginx:将SSL连接转发到另一台服务器

10

我有一个主nginx服务器,根据传入的服务器名称决定将请求路由到哪个服务器。对于两个辅助服务器,这个主nginx服务器也持有SSL证书和密钥。第三个服务器持有自己的证书和密钥,因为这些证书经常需要更新。

现在我的问题是如何配置主nginx服务器,以便将所有针对第三个服务器的请求转发到该服务器。我无法将第三个服务器的证书和密钥复制到主服务器上,因为它们会经常更改。

overview servers and http(s) connections

2个回答

8

5
这里有一个可能可行的配置方案。通过主服务器代理并将所有内容转发到Server3。使用ssl端口,但关闭ssl功能。
server {
    listen      443;
    server_name  myserver.mydomain.whatever;

    ssl         off;

    access_log      /var/log/nginx/myserver.access.log;
    error_log       /var/log/nginx/myserver.error.og;

    keepalive_timeout   60;

    location / {
        set $fixed_destination $http_destination;
        if ( $http_destination ~* ^https(.*)$ )
        {
            set $fixed_destination http$1;
        }

        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;
        proxy_set_header    Destination $fixed_destination;
        # Fix the “It appears that your reverse proxy set up is broken" error.
        # might need to explicity set https://localip:port
        proxy_pass          $fixed_destination;
        # force timeout if backend died.
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        proxy_read_timeout  90;
        proxy_redirect http:// https://;
    }
}

谢谢你的帮助。我不太确定我是否完全理解了。关于 listen 80; 的服务器定义,我应该怎么做?将其重定向到主 nginx 服务器上的 443 然后使用您的代码示例吗?在您的示例中,您在哪里指定将请求转发到哪个内部 IP? - J J
我已经进行了双重测试。不管哪种方式,都会在 Nginx 日志中出现错误,指出 2015/10/22 11:34:21 [error] 18229#0: *57916 invalid URL prefix in "", client: xxx.xxx.xxx.xxx, server: my_server_name, request: "GET / HTTP/1.1$ 或者浏览器直接显示无法建立安全连接并拒绝连接。 - J J
3
看起来不可能。Nginx不支持正向代理。https和nginx作为正向代理 - wolfhammer

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接