2015-11-24 72 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 + - 定额。我希望这有帮助。