server {
        listen   85;
        server_name  localhost;
        location ~.*\.(?:json) {
                root   /usr/local/runwaygo/wmsWeb/dist;
                try_files $uri $uri/ /index.html;
            #设置允许跨域
            add_header Access-Control-Allow-Origin *; 
            add_header Access-Control-Allow-Methods "POST, GET, OPTIONS";
            add_header Access-Control-Allow-Headers "Origin, Authorization, Accept";
        }
        location /api{
                 proxy_pass http://127.0.0.1:9001/;
        }
        location / {
                root   /usr/local/runwaygo/wmsWeb/dist;
                try_files $uri $uri/ /index.html;
                gzip_static on;
        }
        //  #通配符 * 与 前端代码 axios.defaults.withCredentials= true; 冲突
        // 提示  ...has been blocked by CORS policy: The value of the 'Access-Control-Allow-Origin' header in the response must not be the wildcard '*' when the request's credentials mode is 'include'. The credentials mode of requests initiated by the XMLHttpRequest is controlled by the withCredentials attribute.
        // 1、不携带cookie的话,直接去前端携带cookie代码 2、更改本地及服务端nginx的localhost为127.0.0.1可解决通配符问题。
}


Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐