Nginx 跨域设置 Access-Control-Allow-Origin 无效的解决办法
2017-10-27 23:45
726 查看
nginx 版本 1.11.3 使用大家说的以下配置,验证无效,跨域问题仍然存在 add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Credentials' 'true'; add_header 'Access-Control-Allow-Methods' 'GET,POST'; 使用以下配置,生效。 if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, 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-Max-Age' 1728000; add_header 'Content-Type' 'text/plain charset=UTF-8'; add 4000 _header 'Content-Length' 0; return 204; } if ($request_method = 'POST') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; } if ($request_method = 'GET') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type'; }
相关文章推荐
- Nginx 跨域设置 Access-Control-Allow-Origin 无效的解决办法
- 黄聪:Access-Control-Allow-Origin,JS跨域解决办法
- 找到的OpenLayers跨域访问WFS服务出现No 'Access-Control-Allow-Origin' header is present...错误的一种解决办法
- 跨域调用Access-Control-Allow-Origin报错的解决办法
- 前端开发中使用nginx跨域解决No Access-Control-Allow-Origin header localhost:63342 is not allowed access
- 设置Access-Control-Allow-Origin,解决多域名跨域问题
- angular4 通过httpclient调http接口,出现access-control-allow-origin跨域问题解决办法
- 利用Access-Control-Allow-Origin响应头解决跨域请求
- HTML5 Access-Control-Allow-Origin解决跨域问题
- (服务端处理)ajax 设置Access-Control-Allow-Origin实现跨域访问
- ajax 设置Access-Control-Allow-Origin实现跨域访问
- ajax 设置Access-Control-Allow-Origin实现跨域访问
- 解决nodejs socket.io is not allowed by Access-Control-Allow-Origin 跨域问题
- ajax 设置Access-Control-Allow-Origin实现跨域访问
- Ajax通过设置Access-Control-Allow-Origin来实现跨域
- 关于Access-Control-Allow-Origin的跨域错误解决
- ajax 设置Access-Control-Allow-Origin实现跨域访问
- 利用Access-Control-Allow-Origin响应头解决跨域请求原理
- Ajax 设置Access-Control-Allow-Origin实现跨域访问
- 解决Ajax跨域问题:Origin xx is not allowed by Access-Control-Allow-Origin.