飞天使-nginx跨域问题

跨域问题很常见,一般在前端配置中新增下面配置,可以忽略后端的跨域问题

  location /
    {
        add_header Access-Control-Allow-Origin * always;
        add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS, PUT, PATCH, DELETE' always;
        add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization' always;
        proxy_hide_header Access-Control-Allow-Origin;
        proxy_hide_header access-control-allow-headers;
        proxy_hide_header access-control-request-method;

        if ($request_method = 'OPTIONS') {
            return 204;
        }
        proxy_pass  http://import_upstream;
        proxy_connect_timeout 100;
        proxy_read_timeout 100;
        proxy_send_timeout 100;
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        proxy_buffers           16 1024k;
        proxy_buffer_size       1024k;
        proxy_busy_buffers_size 1024k;

        proxy_redirect     off;
        proxy_set_header   Host             $host;
        proxy_set_header   X-Real-IP        $remote_addr;
        proxy_set_header   X-Forwarded-For  $remote_addr;
    }
}

猜你喜欢

转载自blog.csdn.net/startfefesfe/article/details/132686162