windows系统下 nginx、tomcat部署javaweb项目appscan扫描出漏洞 CORS策略根据任意初始头进行设置系统只允许https172161587、https172161589为可信站点如何设置
要解决CORS策略根据任意初始头进行设置的问题,并且只允许https:172.16.15.87和https:172.16.15.89作为可信站点,你可以按照以下步骤进行设置:
-
打开Nginx配置文件,通常位于nginx安装目录下的conf文件夹中,找到并编辑nginx.conf文件。
-
在http节点下添加以下配置,用于设置CORS策略:
http {
...
# 允许的域名列表
map $http_origin $allow_origin {
default "";
https://172.16.15.87 "https://172.16.15.87";
https://172.16.15.89 "https://172.16.15.89";
}
# 设置CORS响应头
server {
...
location / {
if ($allow_origin != "") {
add_header Access-Control-Allow-Origin $allow_origin;
add_header Access-Control-Allow-Credentials true;
}
...
}
}
}
-
保存并关闭nginx.conf文件。
-
打开Tomcat的配置文件,通常位于Tomcat安装目录下的conf文件夹中,找到并编辑server.xml文件。
-
在Connector节点中添加以下配置,用于支持HTTPS连接:
<Connector port="443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true">
<SSLHostConfig>
<Certificate certificateKeyFile="路径/私钥.key"
certificateFile="路径/证书.crt"
certificateChainFile="路径/证书链.crt"
type="RSA" />
</SSLHostConfig>
</Connector>
替换路径为你的SSL证书和私钥文件的实际路径。
-
保存并关闭server.xml文件。
-
重启Nginx和Tomcat服务,以使配置生效。
这样,Nginx将会根据请求的初始头设置CORS策略,并且只允许https:172.16.15.87和https:172.16.15.89作为可信站点
原文地址: https://www.cveoy.top/t/topic/ig23 著作权归作者所有。请勿转载和采集!