2015-11-24 79 views
0

我今天已經安裝了SSL證書,並且它完美地工作,頁面通過https://工作正常。Apache SSL配置休息HTTP

我已經在我的網站.conf中重定向到端口80重定向到https,但它不工作。

此外,如果我去http://www.example.org(根),它卡在重定向循環。 去http://www.example.org/test.htm去相同的網址減去最後一個/。例如http://www.example.orgtest.htm/(斜槓移動到盡頭)

這真的是打破了我的球,我真的希望你們有一些線索。

這裏是我的.conf文件

NameVirtualHost *:80 
<VirtualHost *:80> 
    ServerName example.org 
    Redirect permanent/https://www.example.org 
</VirtualHost> 


<VirtualHost _default_:443> 

    # Admin email, Server Name (domain name), and any aliases 
    ServerAdmin [email protected] 
    ServerName example.org 
    ServerAlias www.example.org 

    # Index file and Document Root (where the public files are located) 
    DirectoryIndex index.html index.org 
    DocumentRoot /var/www/example.org/html 

    # SSL settings 
    SSLEngine on 
    SSLCertificateFile /etc/ssl/certs/www_example_org.crt 
    SSLCertificateKeyFile /etc/ssl/digicert/example.key 
    SSLCACertificateFile /etc/ssl/certs/DigiCertCA.crt 

    # Log file locations 
    LogLevel warn 
    ErrorLog /var/www/example.org/log/error.log 
    CustomLog /var/www/example.org/log/access.log combined 
</VirtualHost> 

回答

0

以及我的工作了太多的眼淚後,我缺少 ServerAlias www.example.org

端口爲80,由於本爲HSTS頭,雖然,我將DEF使用。歡呼聲

1

你的配置看起來對我罰款。也許,你應該附加一個/這樣的:Redirect permanent/https://www.example.org/

而不是使用Redirect permanent的,你也可以使用mod_rewrite

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L] 

對於這個工作,你必須已經安裝了mod_rewrite模塊。

如果您想要使用force https,另一種方法是在您的Apache配置中設置HSTS-Header。然後,瀏覽器知道您的網站可以使用https,並且會自動將所有流量重定向到您的https地址。您可以設置此頭用下面的命令:

Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload" 

在一般情況下,我會建議與SSLLabs審覈您的SSL配置。如果你的配置沒問題,你應該得到一個A + - 定額。我希望這有幫助。