【问题标题】:zf2 apache aws elb http to httpszf2 apache aws elb http 到 https
【发布时间】:2015-06-27 13:54:15
【问题描述】:

我看过:

Rerouting all http traffic to https with AWS ELB

http://www.emind.co/how-to/how-to-force-https-behind-aws-elb

Redirecting EC2 elb from http to https

我的负载均衡器监听端口如下所示:

HTTP (incoming) -> HTTP (instance)
HTTPS (incoming) -> HTTP (instance)

这是我目前所拥有的:

RewriteEngine On

# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/elbcheck.html https://%{SERVER_NAME}%{REQUEST_URI}

RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

这适用于将 http 重定向到 https,但它只会转到索引页面。它没有触发应用程序,所有其他页面都以 404 形式返回。

任何建议都将不胜感激,我一直在努力解决这个问题太久了。

***************更新***************

这是我的.htaccess 最终的样子:

RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTP_USER_AGENT} !^ELB-HealthChecker
RewriteRule (.*) https://sitename.com%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteRule ^.*$ index.php [NC,L]

希望这会有所帮助!

【问题讨论】:

    标签: .htaccess amazon-web-services amazon-ec2 zend-framework2 amazon-elb


    【解决方案1】:

    我认为这是最好的解决方案,而不是提出自己的答案并在适当的时候给予赞扬。

    ELB and Apache configuration for HTTPS website

    【讨论】:

      【解决方案2】:

      还要确保通过 AWS 控制台将侦听器添加到 ELB。端口 80 和端口 443 的侦听器。

      【讨论】:

        猜你喜欢
        • 2018-02-28
        • 2020-11-13
        • 2017-09-30
        • 1970-01-01
        • 2018-04-15
        • 2018-03-07
        • 1970-01-01
        • 2019-01-23
        • 1970-01-01
        相关资源
        最近更新 更多