【问题标题】:how to allow ec2 health check through .htaccess while redirecting to https如何在重定向到 https 时允许通过 .htaccess 进行 ec2 运行状况检查
【发布时间】:2017-02-14 00:04:46
【问题描述】:

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

1 允许在不重定向到 https 的情况下点击 EC2 运行状况检查 URL 2 将所有非 https 流量重定向到 https 3 将调用重定向到 / 到 /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

如果您有任何建议,请告诉我如何让它工作。

【问题讨论】:

  • 我会尝试一个简单的RewriteRule ^healthcheck\.html$ - [L]——当请求的 URL 是 healthcheck.html 时,不要重写任何东西 (-),并将其作为最后一条规则。这应该不需要任何额外的 RewriteConds。

标签: .htaccess ssl elastic-load-balancer


【解决方案1】:

感谢您的回复。在我阅读之前,我发现另一篇文章提供了一个对我有用的解决方案。如果 url 是我的健康检查页面的 url,我只是添加了另一个条件以不应用 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]

【讨论】:

    猜你喜欢
    • 2014-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多