gpt4 book ai didi

ssl - Nginx 通过 https 代理到服务器 - 证书上的主机名与主机 header 不同

转载 作者:太空宇宙 更新时间:2023-11-03 12:48:20 24 4
gpt4 key购买 nike

我想在服务器 1 上接收来自 https://example.com 的流量。然后我想通过 https 将该流量代理到服务器 2。服务器 2 已为 Nginx 设置了确切的与服务器 1 相同的 tls 证书和 key ,因此理论上它应该能够满足请求。但是,当服务器 2 上的 Nginx 尝试将请求代理到服务器 2 时,它会将请求发送到 server2.example.com,这与证书上的通用名称不同,后者只是 example .com.

有没有办法将 nginx 配置为期望主机(在 tls 握手期间)提供的 tls 证书上的名称(在 tls 握手期间)它正在代理请求与它正在代理的主机地址不同?

服务器 1 上的示例配置:

server {
listen 443 ssl;
server_name example.com;

ssl_certificate /srv/tls/example.com.crt;
ssl_certificate_key /srv/tls/example.com.key;

location / {
proxy_pass https://server2.example.com;
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 https;
}
}

服务器 2 上的示例配置:

server {
listen 443 ssl;
server_name example.com;

ssl_certificate /srv/tls/example.com.crt;
ssl_certificate_key /srv/tls/example.com.key;

location / {
proxy_pass http://localhost:12345;
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 https;
}
}

来自服务器 1 的 curl 示例:

$ curl https://server2.example.com/chat -H "Host: example.com"
curl: (51) Unable to communicate securely with peer: requested domain name does not match the server's certificate.

如果需要,我可以生成一个新的自签名证书并在服务器 2 上使用它。但是,我认为只更改 Nginx 配置会更快。如果无法更改配置,我将创建一个新证书。

最佳答案

您可以使用 proxy_ssl_name 指令指定代理主机证书的服务器名称。

例如:

location / {
proxy_pass https://server2.example.com;
proxy_set_header Host $host;
proxy_ssl_name $host;
...
}

参见 this document了解详情。

关于ssl - Nginx 通过 https 代理到服务器 - 证书上的主机名与主机 header 不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49709411/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com