java项目中怎么减少options请求的影响,或者禁掉options请求
如果想禁用 option 请求的话,可以在 nginx 中进行配置
在 nginx.conf 配置文件中,增加如下内容:
if ($request_method ~* OPTIONS) {
return 403;
}
重启 nginx 服务
/usr/local/nginx/sbin -s reload
systemctl restart nginx
service nginx restart
功能验证
使用如下命令可验证:
curl -v -X OPTIONS http://localhost:8080/
这是前后端分离的项目吧,这种方式,options是去不掉的,不过这种请求不影响性能,或者说可以忽略不计。