【问题标题】:Redirecting from Http to Https with AWS's ELB in Chrome and FireFox在 Chrome 和 FireFox 中使用 AWS 的 ELB 从 Http 重定向到 Https
【发布时间】:2017-09-28 12:37:38
【问题描述】:

我已经使用 ELB 在 AWS 上设置了从 http 到 https 的重定向。流程如下。

在 .htaccess 文件中,放入以下 ​​X-Forwarded-Proto 代码

<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 上仍然不起作用吗?

【问题讨论】:

  • 是的,我已经清除了几次浏览器缓存。 FireFox 还是一样。
  • 浏览器没有显示它不安全。但是我还没有看到前面的https。
  • 我收到 AWS 的回复,提示 ELB 只是使用 X-Forwarded-Proto 插入重定向信息。所以重定向的实际实现需要在实例中发生,在 apache 中。我需要弄清楚如何。

标签: .htaccess amazon-web-services http-redirect amazon-elb


【解决方案1】:

我解决这个问题很久了,现在可以让它成功运行。 我喜欢分享我所做的事情如下。

(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 

【讨论】:

    猜你喜欢
    • 2017-09-30
    • 1970-01-01
    • 2018-03-07
    • 1970-01-01
    • 2023-03-22
    • 2018-04-15
    • 2019-01-23
    • 2018-08-18
    • 1970-01-01
    相关资源
    最近更新 更多