2017-06-02 96 views
0

我正在使用具有apache容器和燈容器的docker。燈容器包含應用程序代碼,Apache容器具有如下虛擬主機配置信息。從Docker容器返回響應時返回https url的問題

<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響應。

如何實現這一目標?

回答

0

燈正在接收來自Apache的http請求,所以您必須告訴Lamp,來自客戶端的初始請求是通過https。

嘗試在HTTPS虛擬主機定義添加此:

RequestHeader set X-Forwarded-Proto "https" 

有了這個頭,燈應該明白,客戶確實通過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>