apache .htaccess 替代“deny from XXXX”?

发布于 2024-09-30 04:26:11 字数 200 浏览 1 评论 0原文

我有 nginx 反向代理到 apache,如果我将“拒绝来自 111.111.111.111”添加到我的 htaccess,它仍然允许它们通过,因为 nginx 不会转发访问者的 remote_addr ip。

是否有规则或其他内容可以添加到 htaccess,以便如果访问者 IP 地址使用“HTTP_X_REAL_IP”,我可以将它们重定向到静态 html 页面?

I have nginx reverse proxying to apache and if I add "Deny from 111.111.111.111" to my htaccess it still allows them through as nginx doesn't forward the remote_addr ip of the visitor.

Is there a rule or something I can add to htaccess so if an the visitors ip address using "HTTP_X_REAL_IP" I can just redirect them to a static html page?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揪着可爱 2024-10-07 04:26:11

像这样的东西应该有效:

RewriteEngine On
RewriteCond %{HTTP:HTTP_X_REAL_IP} 111.111.111.111
RewriteRule (.*) - [F,L]

重写规则将向他们发送 403 禁止响应,而不替换另一个 url。这应该会导致显示默认的 403 错误页面。

您可以使用以下方法指定 403 错误页面:

ErrorDocument 403 /path-to-file

请参阅: http://httpd .apache.org/docs/2.0/mod/mod_rewrite.html#rewritecondhttp://httpd.apache.org/docs/2.0/mod/core.html#errordocument 了解更多信息。

Something like this should work:

RewriteEngine On
RewriteCond %{HTTP:HTTP_X_REAL_IP} 111.111.111.111
RewriteRule (.*) - [F,L]

That rewrite rule will send them a 403 forbidden response without substituting another url. This should cause your default 403 error page to be shown.

You can specify your 403 error page using this:

ErrorDocument 403 /path-to-file

see: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond and http://httpd.apache.org/docs/2.0/mod/core.html#errordocument for more info.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文