Nginx 关闭/屏蔽 PUT、DELETE、OPTIONS 请求

1、修改 nginx 配置

在 nginx 配置文件中,增加如下配置内容:

if ($request_method !~* GET|POST|HEAD) {
    
    
 return 403;
}

修改效果如下:
在这里插入图片描述

2、重启 nginx 服务

systemctl restart nginx

或者

service nginx restart

在这里插入图片描述

3、功能验证

使用如下方式验证(可以使用 IntelliJ IDEA 自带的 Http request 工具,很方便,强烈推荐!!!)

DELETE http://localhost:8080/
#PUT http://localhost:8080/
#OPTIONS http://localhost:8080/

执行效果如下:
在这里插入图片描述


猜你喜欢

转载自blog.csdn.net/aikudexiaohai/article/details/133224863