xxxxx

Nginx 反向代理解决跨域问题

server {
    listen       8080;
    server_name  localhost;
    
    location / {
        proxy_pass http://111.111.111.111:8080;  # 代理的地址
        proxy_http_version 1.1;
        proxy_set_header Connection "";
        add_header Access-Control-Allow-Origin *;
        add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
        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';

        if ($request_method = 'OPTIONS') {
            return 204;
        }
        # root   html;
        # index  index.html index.htm;
    }
}

如果请求部分资源错误,报如下错:

upstream sent invalid chunked response while reading upstream,

那么加上 proxy_http_version 1.1; proxy_set_header Connection "";

posted @ 2020-05-23 11:36  St4ndAlone  阅读(161)  评论(0编辑  收藏  举报
i still love you