zf2 apache aws elb http 到 https
zf2 apache aws elb http to https
我看过:
http://www.emind.co/how-to/how-to-force-https-behind-aws-elb
我的负载均衡器侦听端口如下所示:
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}:: ^(/.+)(.+)::$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
这适用于将 http 重定向到 https,但它只会转到索引页面。它没有触发应用程序,所有其他页面返回为 404s。
如有任何建议,我将不胜感激,我在这个问题上思考的时间太长了。
***************更新***************
这是我的 .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/ [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]
希望对您有所帮助!
我认为这是最好的解决方案,而不是提出我自己的答案并给予应有的信任。
还要确保通过 AWS 控制台将监听器添加到 ELB。端口 80 和端口 443 的侦听器。
我看过:
http://www.emind.co/how-to/how-to-force-https-behind-aws-elb
我的负载均衡器侦听端口如下所示:
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}:: ^(/.+)(.+)::$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
这适用于将 http 重定向到 https,但它只会转到索引页面。它没有触发应用程序,所有其他页面返回为 404s。
如有任何建议,我将不胜感激,我在这个问题上思考的时间太长了。
***************更新***************
这是我的 .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/ [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]
希望对您有所帮助!
我认为这是最好的解决方案,而不是提出我自己的答案并给予应有的信任。
还要确保通过 AWS 控制台将监听器添加到 ELB。端口 80 和端口 443 的侦听器。