如何在重定向到https时通过.htaccess进行ec2健康检查

时间:2017-02-13 15:41:08

标签: .htaccess ssl elastic-load-balancer

我正在尝试创建一个执行以下操作的.htaccess文件:

1允许在不重定向到https的情况下命中EC2运行状况检查URL 2将所有非https流量重定向到https 3将呼叫重定向到/ to / auth / app / public / app(使用https)

第2项和第3项工作正常,但很快健康检查失败,服务器不再响应。这是我的.htaccess文件的内容:

RewriteEngine On

#one attempt that didn't work
#RewriteCond %{HTTP_HOST} !^my\.domain\.com$ [NC]
#RewriteCond %{REQUEST_URI} !^/healthcheck.html$
#RewriteRule ^ http://my.domain.com/$1 [R=301,L]

#another attempt that didn't work
#RewriteCond %{HTTP_HOST} !$ [NC]
#RewriteCond %{REQUEST_URI} !^/healthcheck.html$
#RewriteRule ^(.*)$ /$1 [L,QSA]

#this works
RewriteRule ^$ https://my.domain.com/auth/app/public/app/ [L]

#this works
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://my.domain.com%{REQUEST_URI} [L]

前两次评论的尝试来自我在https://serverfault.com/questions/470015/how-should-i-configure-my-elb-health-check-when-using-namevirtualhosts-and-redir找到的示例 和https://serverfault.com/questions/470015/how-should-i-configure-my-elb-health-check-when-using-namevirtualhosts-and-redir/597541#597541

如果您对我的工作方式有任何建议,请与我们联系。

1 个答案:

答案 0 :(得分:0)

感谢您的回复。在我阅读之前,我发现另一篇文章提供了一个适合我的解决方案。如果网址是我的健康检查页面的网址,我只是添加了另一个不应用https重定向规则的条件。这是我的.htaccess文件的工作版本:

RewriteEngine On
RewriteRule ^$ https://my.domain.com/auth/app/public/app/ [L]

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{REQUEST_URI} !^/healthcheck\.html$
RewriteRule ^ https://my.domain.com%{REQUEST_URI} [L]
相关问题