jboss 在Apache服务器上禁用OPTIONS HTTP

j8yoct9x  于 2023-08-05  发布在  Apache
关注(0)|答案(3)|浏览(136)
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选项,但我想保留GETPOST,我想PING我的服务器。
我怎么能那么做?

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

uajslkp6

uajslkp61#

无法使用RewriteCond禁用OPTIONS方法。必须使用LimitExcept指令禁用。
下面是可以在Apache配置之外添加的代码段:

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

字符串
请不要忘记重新启动Web服务器:)

pepwfjgg

pepwfjgg2#

如果您想将其应用于特定项目:
简单地将这些行添加到.htaccess文件对我来说很有效:

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

字符串
要做到这一点,请确保您已经启用了mod_rewrite,并且在这些行之前使用了RewriteEngine On

u7up0aaq

u7up0aaq3#

要在Apache server上关闭HTTP OPTIONS方法,同时允许GETPOSTPING请求,您可以在httpd.conf文件中使用以下配置:

RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^OPTIONS$
RewriteRule .* - [R=405,L]

<LocationMatch "/your_ping_endpoint">
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</LocationMatch>

字符串
/your_ping_endpoint替换为您要用于PING请求的实际URL端点。此配置将为任何OPTIONS请求返回405Method not allowed)响应,并拒绝从localhost127.0.0.1)以外的任何位置访问your_ping_endpointURL
此外,确保通过运行以下命令在Apache中启用重写模块:

sudo a2enmod rewrite


完成这些更改后,重新启动Apache服务器以使配置生效。

相关问题