我们的一个客户想通过他的服务器运行一个网站到我们的has服务器,所以网站有他的服务器的公共ip而不是我们的。这在http上运行得很好,但在https上就变得狂暴了。
客户端的服务器使用Apache运行Virtualmin,我们的服务器使用php-fpm运行Nginx。我们尝试为客户端服务器和我们的We服务器设置相同的证书,但此站点一直显示握手错误。
两个服务器使用完全相同的证书。
客户端的Apache配置:
ProxyPass / http://1.2.3.4:8123/
ProxyPassReverse / http://1.2.3.4:8123/
SSLProxyEngine on
SSLProxyCheckPeerCN on
SSLProxyCheckPeerExpire on
SSLEngine on
SSLCertificateFile /foo/bar/ssl.cert
SSLCertificateKeyFile /foo/bar/ssl.key
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCACertificateFile /foo/bar/ssl.ca我们的Nginx配置:
server {
listen 8123;
server_name some.site wwww.some.site;
ssl_certificate /foo/bar/ssl.crt;
ssl_certificate_key /foo/bar/ssl.crt
ssl_prefer_server_ciphers on;
root /var/www/some.site/public;
index index.php;
charset utf-8;
location ~ /\. {
deny all;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Host $host;
}
}我们想让这个工作,以便我们可以使用https://1.2.3.4:8123/作为代理地址,以避免MITM攻击,并能够通过https://some.site的网站服务。
发布于 2019-09-05 05:45:46
在nginx中创建一个单独的vhost时,我发现证书没有正确设置。curl -I -L https://1.2.3.4:8483返回了curl: (60) SSL certificate problem: unable to get local issuer certificate。运行openssl verify ssl.crt抛出了一个错误,而openssl verify -CAfile ssl.ca-bundle ssl.crt没有,这证实了缺少ca-bundle (source of verify commands)。
作为stated,nginx不支持单独的ca文件,所以我创建了一个新文件ssl.combined并将其添加到ssl_certificate指令:cp ssl.crt ssl.combined; cat ssl.ca-bundle >> ssl.combined。柯尔现在很高兴。
Apache也有同样的问题,但确实支持ca-files。我使用SSLCertificateChainFile添加了ssl.ca-bundle。
最后,使用sample configuration,我找到了罪魁祸首:ProxyPreserveHost On是一切正常工作所必需的,这会导致Apache发送正确的Host-header over Proxy,这反过来又会使握手正常工作。
作为其他人的参考,我在下面添加了我的最终配置:
对于Apache (客户端服务器、反向代理):
[...]
SSLEngine on
SSLCertificateFile /foo/bar/ssl.cert
SSLCertificateKeyFile /foo/bar/ssl.key
SSLCertificateChainFile /foo/bar/ssl.ca
ProxyRequests off
ProxyPreserveHost On
SSLProxyEngine on
SSLProxyCheckPeerCN on
SSLProxyCheckPeerExpire on
ProxyPass / https://1.2.3.4:8483/
ProxyPassReverse / https://1.2.3.4:8483/
<Proxy *>
allow from all
</Proxy>
[...]对于nginx (我们的服务器,转发代理):
server {
listen 8483 ssl;
server_name site.url www.site.url;
ssl on;
ssl_certificate /foo/bar/ssl.combined;
ssl_certificate_key /foo/bar/ssl.key;
ssl_stapling on;
ssl_stapling_verify on;
root /var/www/site.url/public
index index.php;
charset utf-8;
location ~ /\. {
deny all;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Host $host;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include /etc/nginx/fastcgi_params;
}
}https://stackoverflow.com/questions/57786649
复制相似问题