location /{
proxy_pass http://127.0.0.1:8080/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 90;
# add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Origin "$http_origin";
add_header Access-Control-Allow-Methods 'GET, POST, PUT, DELETE, OPTIONS';
add_header Access-Control-Allow-Credentials 'true';
add_header Access-Control-Allow-Headers 'Accept,token, Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, DELETE, PUT, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'Accept,token,Authorization,DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
return 200;
}
}
nginx跨域配置
最新推荐文章于 2025-03-05 11:45:00 发布
本文详细解析了Nginx反向代理的配置方法,包括如何设置代理服务器、跨域请求处理、请求超时时间和头部信息传递等关键参数。通过具体的配置示例,帮助读者理解Nginx在实现负载均衡、提升网站性能和安全性方面的作用。
7135

被折叠的 条评论
为什么被折叠?



