码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx 反向代理解决跨域问题

时间:2020-05-23 13:24:22      阅读:50      评论:0      收藏:0      [点我收藏+]

标签:roo   while   live   cti   modified   headers   connect   ESS   lis   

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

Nginx 反向代理解决跨域问题

标签:roo   while   live   cti   modified   headers   connect   ESS   lis   

原文地址:https://www.cnblogs.com/ingen42/p/12941774.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!