2017-05-01 46 views
0

我已经使用ELB在AWS设置了从http重定向到https。程序如下。在Chrome和FireFox中使用AWS的ELB从Http重定向到https

在该文件中的.htaccess,把下面的X - 转发,原代码

<VirtualHost *:80> 
    RewriteEngine On 
    RewriteCond %{HTTP:X-Forwarded-Proto} !https 
    RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker 
    RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 
</VirtualHost> 

然后.htaccess文件放入该文件夹我的网站停留的index.php里面。

我在Chrome,FireFox和Safari上测试过。 Chrome和Safari都可以工作,但FireFox不支持。

在Chrome和Safari中,当我在浏览器中输入www.domainname.com时,我在浏览器中看到更改为https://www.domainname.com。和Safari一样。

但是在Chrome中,当我输入www.domainname.com时,页面将加载http://www.domainname.com。即使我输入http://www.domainname.com,它本身也改为https://www.domainname.com

什么可能是错的? FireFox的重定向功能仍然无法使用吗?

+0

YesI清除浏览器缓存已经几次了。 FireFox仍然是一样的。 – batuman

+0

浏览器不显示它是不安全的。但是我没有在前面看到https。 – batuman

+0

我从AWS获得了一条线索的回复,那就是ELB只是使用X-Forwarded-Proto插入重定向信息。所以实际的重定向实现需要在实例中发生,在Apache中。我需要弄清楚如何。 – batuman

回答

0

我正在解决这个问题很长一段时间,现在可以使其成功运行。 我喜欢分享我所做的如下。

(1)Create .htaccess file inside the folder same as root file index.php exists 
(2).htaccess file has 
RewriteEngine On 
RewriteCond %{HTTP:X-Forwarded-Proto} =http 
RewriteRule . https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent] 
(3)Then enable mod_rewrite, try the command line command: 
    sudo a2enmod rewrite 
(4)To make sure mod_rewrite is enabled, update /etc/apache2/apache2.conf file as 
<Directory /var/www/html> 
     Options Indexes FollowSymLinks 
     AllowOverride All 
     Require all granted 
</Directory> 
initially was 
<Directory /var/www/> 
     Options Indexes FollowSymLinks 
     AllowOverride None 
     Require all granted 
</Directory> 

Then you can setup http to https successfully 
You need to restart server as sudo service apache2 restart after update of /etc/apache2/apache2.conf