从docker容器返回响应时发出返回https url的问题

时间:2017-06-02 09:02:48

标签: apache docker lamp docker-machine

我正在使用具有apache容器和灯泡容器的docker。 Lamp容器包含应用程序代码,Apache容器具有虚拟主机配置信息,如下所示。

<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的响应。

如何实现这一目标?

1 个答案:

答案 0 :(得分:0)

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>