2015-11-03 216 views
0

我試圖配置我的apache服務器重定向到https://當用戶瀏覽到http:// url。apache http:重定向到https:

我已經在谷歌周圍搜索,但事情並不完全正常。以下是我已經試過:

Listen 443 
…. 
<VirtualHost *:443> 
    SSLEngine on 
    SSLCertificateFile "/usr/local/apache2/conf/server.crt" 
    SSLCertificateKeyFile "/usr/local/apache2/conf/server.key" 

    SSLProxyEngine On 
    ServerAdmin [email protected] 
    DocumentRoot /usr/local/apache2/htdocs 
</VirtualHost> 

ErrorLog /usr/local/apache2/logs/error.log 
CustomLog /usr/local/apache2/logs/access.log combined 

FallbackResource /index.html 

利用這種結構,這是瀏覽器的響應:

################## Bad Request 

Your browser sent a request that this server could not understand. 
Reason: You're speaking plain HTTP to an SSL-enabled server port. 
Instead use the HTTPS scheme to access this URL, please. 

此外,我已經試過這一個:

<VirtualHost *:443> 
    SSLEngine on 
    SSLCertificateFile "/usr/local/apache2/conf/server.crt" 
    SSLCertificateKeyFile "/usr/local/apache2/conf/server.key" 

    SSLProxyEngine On 
    ServerAdmin [email protected] 
    DocumentRoot /usr/local/apache2/htdocs 

    RewriteEngine On 
    RewriteCond %{HTTPS} off 
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 
</VirtualHost> 

但沒有有效(相同的瀏覽器響應)。

我在做什麼錯?

感謝

+0

您是否在進行更改時重新啓動Apache?在測試重定向之前,還有值得檢查的是你有正確的https。你可以瀏覽到https網址嗎? –

回答

0

找上了第二個例子我想說重寫部分應該進入標準的主機,*:80 ...

而且,也許是錯誤消息來自沒有服務器準備好能夠通過http傳遞至少重定向...