天天看點

cors nginx 怎麼解決_通過nginx配置解決前端跨域CORS問題

nginx 配置

location ~ ^/dingdang-cms/.*$

{

#add_header 'Access-Control-Allow-Origin' 'http://192.168.2.7:6970' always;

#如果使用此配置則隻能為http://192.168.2.7:6970的域名可以通路

add_header 'Access-Control-Allow-Origin' "$http_origin";

add_header 'Access-Control-Allow-Credentials' 'true' always ;

if ($request_method = 'OPTIONS') {

add_header Access-Control-Max-Age "3600" ;

add_header 'Access-Control-Allow-Origin' 'http://192.168.2.7:6970' always;

#add_header 'Access-Control-Allow-Origin' "$http_origin";

add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type, Access-Control-Expose-Headers, Token, Authorization';

return 200;

}

proxy_pass http://dingdang-cms;

}