Nginx跨域设置Access-Control-Allow-Origin无效的解决办法
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_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'; }
相关推荐
ysmh00 2020-05-14
Caleb0 2019-12-23
墨氺 2018-12-03
HAcSeeking 2018-11-05
yangliuhbhd 2020-09-24
风之羽翼 2020-09-14
luotuofeile 2020-07-28
Strongding 2020-06-25
xuanwenchao 2020-06-14
昊 2020-06-04
ErixHao 2020-05-08
数据库之扑朔迷离 2020-05-06
whyname 2020-04-29
daillo 2020-04-20
踩风火轮的乌龟 2020-04-19
hitxueliang 2020-04-18
hithyc 2020-04-17
snowguy 2020-04-10
zengfanpei 2020-03-08