【问题标题】:Disable OPTIONS HTTP on Apache Server在 Apache 服务器上禁用 OPTIONS HTTP
【发布时间】:2020-11-03 10:39:55
【问题描述】:
Request:
OPTIONS / HTTP/1.1
Host: webcat.staci.com
Connection: Keep-alive
Accept-Encoding: gzip,deflate
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.21 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.21
Accept: */*

Response:
HTTP/1.1 200 OK
Date: Thu, 01 Oct 2015 12:24:59 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Allow: GET,HEAD,POST,OPTIONS,TRACE
Vary: Accept-Encoding,User-Agent
Content-Length: 0
Keep-Alive: timeout=7, max=95
Connection: Keep-Alive
Content-Type: httpd/unix-directory
Set-Cookie: BIGipServerwebcat-ssl=192938503.47873.0000; path=/; httponly; secure

我想在我的 Apache 服务器上禁用 HTTP OPTIONS,但我想保留 GETPOSTPING 我的服务器。

我该怎么做?

我的 httpd.conf:

RewriteEngine On
RewriteCond %{REQUEST_METHOD} !^ (GET,POST,HEAD)
RewriteRule .* – [R=405,L]

【问题讨论】:

  • 到目前为止你尝试过什么?将 Disable OPTIONS HTTP on Apache Server 放入 Google 会返回顶部 sureshk37.wordpress.com/2014/10/01/…
  • 亲爱的先生们,如果您投反对票,请至少给我一个小评论,我的答案可以如何改进。
  • 您是否点击了我发布的链接?您会发现 Stefano 发布的相同解决方案。似乎答案并没有隐藏在互联网上。 ;-)
  • @SubOptimal 我点击链接,但他没有谈论ping
  • 也许添加更多信息,你尝试了什么,你期望什么以及你得到什么。 you want to PING your server 是什么意思? ping your.server.ip 之类的东西?

标签: java apache jboss


【解决方案1】:

无法使用 RewriteCond 禁用 OPTIONS 方法。 您必须使用 LimitExcept 指令禁用。

下面是可以在 Apache 配置之外添加的 sn-p:

<Location />
    <LimitExcept GET POST>
        order deny,allow
        deny from all
    </LimitExcept>
</Location>

请不要忘记重新启动网络服务器:)

【讨论】:

  • 您的解决方案还禁用了ping ?
  • 不,只有使用“禁用 HTTP 方法重写规则”时才会禁用 ping
  • 这不适用于 WordPress 网站。我的 Apache 配置中有推荐的配置,但 WordPress .htaccess 会覆盖它。见这里:stackoverflow.com/questions/66570860/…
【解决方案2】:

如果您想将其应用于特定项目:

只需将这些行添加到对我有用的 .htaccess 文件:

RewriteCond %{REQUEST_METHOD} ^(OPTIONS)
RewriteRule .* - [F]

为此,请确保您已启用 mod_rewrite 并在这些行之前使用 RewriteEngine On

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-07-02
  • 1970-01-01
  • 2020-01-21
  • 2011-12-27
  • 2019-04-16
相关资源
最近更新 更多