通过nginx配置解决前端跨域CORS问题

2019-03-06  本文已影响0人  jerryloong

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;
                }

上一篇下一篇

猜你喜欢

热点阅读