如果 cookie 不存在,则阻止站点的正确方法 apache 2.4

Correct way to block a site if a cookie isn't present apache 2.4

我在节点应用程序后面使用 apache 2.4.12 (Ubuntu 15.10) 作为 oauth2 代理。该应用程序在登录前发送大量未经身份验证的请求 b/c 它不知道自己未经过身份验证(它不知道 know/care 关于代理),这会创建大量可能导致问题的大型 cookie。

我想做的是说如果特定的 cookie 不存在 (mod_auth_openidc_session)——这意味着它还没有被授权——阻止对我的服务器的所有请求。到目前为止我有这个但我不确定这是否正确(因为条件需要时间来重现):

RewriteEngine On
RewriteCond %{HTTP_COOKIE} !mod_auth_openidc_session
RewriteRule .*my.server.com.* [F]

这是我想要的吗?:

阻止对 http(s)://my.server.com/ 或 http(s)://my.server.com/login 等的所有请求,除非 cookie mod_auth_openidc_session存在。

RewriteCond %{HTTP_HOST} ^my\.server\.com$
RewriteCond %{HTTP_COOKIE} !mod_auth_openidc_session
RewriteCond %{REQUEST_URI}  ^/websocketpath            [NC]
RewriteRule (.*)  [F,L,NC]

所以,这对我有用。现在所有未经授权的请求似乎都被阻止了,这些请求正在创建大量会话状态。我从 serverfault 的好心人那里得到了答案:

same question at serverfault