从Docker容器返回响应时,返回https url

我使用的Docker有一个Apache容器和一个灯容器。 灯容器包含应用程序代码,Apache容器具有如下的虚拟主机configuration信息。

<VirtualHost *:80> ServerName example.com Redirect permanent / https://example.com/ </VirtualHost> <VirtualHost *:443> ProxyPreserveHost on ProxyPass / http://172.18.0.25/ ProxyPassReverse / http://172.18.0.25/ SSLProxyEngine on SSLEngine on SSLProxyVerify none SSLProxyCheckPeerCN off SSLProxyCheckPeerName off SSLProxyCheckPeerExpire off SSLProtocol All -SSLv2 -SSLv3 SSLCertificateFile /etc/ssl/certs/STAR_example_com.crt SSLCertificateKeyFile /etc/ssl/certs/example_wildcard_private.key SSLCertificateChainFile /etc/ssl/certs/STAR_example_com.ca-bundle RewriteEngine On RewriteCond %{HTTP:Authorization} ^(.*) RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] </VirtualHost> 

问题:当我向https://example.com发出请求时,则响应apache容器返回来自http://example.com而不是https://example.com的响应。

如何做到这一点?

Lamp正在接收来自Apache的http请求,所以您必须告诉Lamp,来自客户端的初始请求是通过https。

尝试在https虚拟主机定义中添加此项:

 RequestHeader set X-Forwarded-Proto "https" 

有了这个头文件,Lamp应该明白客户端通过https做了请求,所以它也会通过https来回答。

所以,你的虚拟主机定义应该如下所示:

 <VirtualHost *:80> ServerName example.com Redirect permanent / https://example.com/ </VirtualHost> <VirtualHost *:443> ProxyPreserveHost on ProxyPass / http://172.18.0.25/ ProxyPassReverse / http://172.18.0.25/ SSLProxyEngine on SSLEngine on SSLProxyVerify none SSLProxyCheckPeerCN off SSLProxyCheckPeerName off SSLProxyCheckPeerExpire off SSLProtocol All -SSLv2 -SSLv3 SSLCertificateFile /etc/ssl/certs/STAR_example_com.crt SSLCertificateKeyFile /etc/ssl/certs/example_wildcard_private.key SSLCertificateChainFile /etc/ssl/certs/STAR_example_com.ca-bundle RewriteEngine On RewriteCond %{HTTP:Authorization} ^(.*) RewriteRule .* - [e=HTTP_AUTHORIZATION:%1] RequestHeader set X-Forwarded-Proto "https" </VirtualHost>