nginx跨域配置
Linux 2023/3/23 21:15:32 点击:不统计
如何在nginx 配置中 设置 跨域跨域访问资源等内容,看下面详细配置
在nginx 对应的的server 站点中配置
server {
servername forasp.cn;
root /root;
location / {
if ($request_method = OPTIONS ) {
add_header "Access-Control-Allow-Origin" *;
add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD";
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
add_header 'Access-Control-Max-Age' 600;
return 200;
}
}
}
或者直接配置 跨域信息
server {
servername forasp.cn;
root /root;
location / {
add_header "Access-Control-Allow-Origin" *;
add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS, HEAD";
add_header "Access-Control-Allow-Headers" "Authorization, Origin, X-Requested-With, Content-Type, Accept";
add_header 'Access-Control-Max-Age' 600;
}
}
·上一篇:网站监控shell脚本 >> ·下一篇:nginx 负载均衡 >>