【发布时间】:2018-09-17 11:06:44
【问题描述】:
我想在服务器 1 上的 https://example.com 接收流量。然后我想通过 https 将该流量代理到服务器 2。服务器 2 设置了 Nginx,使用与服务器 1 完全相同的 tls 证书和密钥,所以它理论上应该能够满足请求。但是,当服务器 2 上的 Nginx 尝试将请求代理到服务器 2 时,它会将请求发送到 server2.example.com,这与证书上的通用名称不同,即 example.com。
有没有办法配置 nginx 以期望它正在代理请求的主机(在 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 配置会更快。如果无法更改配置,我将创建一个新证书。
【问题讨论】: