location ^~/api/v1 {
add_header'Access-Control-Allow-Origin'"$http_origin";
add_header'Access-Control-Allow-Methods''GET, POST, PUT, DELETE, OPTIONS';
add_header'Access-Control-Allow-Headers''DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type ';
add_header'Access-Control-Allow-Credentials''true';
if($request_method='OPTIONS') {
add_header'Access-Control-Allow-Origin'"$http_origin";
add_header'Access-Control-Allow-Methods''GET, POST, PUT, DELETE, OPTIONS';
add_header'Access-Control-Allow-Headers''DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type ';
add_header'Access-Control-Allow-Credentials''true';
add_header'Access-Control-Max-Age'1728000;# 20 天
add_header'Content-Type''text/html charset=UTF-8';
add_header'Content-Length'0;
return200;
}
# 这下面是要被代理的后端服务器,它们就不需要修改代码来支持跨域了
proxy_passhttp://127.0.0.1:8085;
proxy_set_headerHost$host;
proxy_redirectoff;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
proxy_connect_timeout60;
proxy_read_timeout60;
proxy_send_timeout60;
}
NGINX 支持跨域请求配置
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- 当本地URL已经用Nginx代理,例如http://vue-native.guahao-inc.com:9096 ...
- 今天用sanic写前后端分离的项目时,用pycharm本地调试遇到ajax跨域问题。从网上搜索解决方案,用ge...
- 场景 使用webpack-dev-server驱动前端项目时,开发工程中由于访问的webpack-dev-serv...