这个问题在这里已经有了答案:
How to force https on elastic beanstalk?
(22 个回答)
3年前关闭。
我已将 Elastic Beanstalk 环境配置为将所有页面重定向到 https,重定向有效,但是,实例未通过运行状况检查并被终止,您知道如何配置重写规则吗?
我的配置:
NameVirtualHost *:80
<VirtualHost *:80>
.
.
.
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule !/_hostmanager/healthcheck https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</VirtualHost>
最佳答案
除了运行状况检查之外,Elastic Beanstalk 还需要访问多个 hostmananger URL。 Grepping /var/log/httpd/elasticbeanstalk-access_log
, 我看到对 /_hostmanager/tasks
的请求和 /_hostmanager/healthcheck
.
这是我添加到 /etc/httpd/sites/elasticbeanstalk
的规则在我的 EC2 实例上:
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} !^/status$
RewriteCond %{REQUEST_URI} !^/version$
RewriteCond %{REQUEST_URI} !^/_hostmanager/
RewriteRule . https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
请注意,我还允许非 https 流量进入我的
/status
和 /version
页。我实际上在使用 /status
作为实际的健康检查查找 URL,因此让流量跳过重写将避免重定向并使状态查找更快(我假设)。
关于apache - 如何在不通过健康检查的情况下在亚马逊 Elastic Beanstalk 上强制使用 https,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6858492/