nginx跨域(网上找的)

upstream xxx_gateway {
    server 127.0.0.1:60000;
}


server {
    listen 80;
    server_name 网址;

    location / {
        set $origin '*';
        if ($http_origin) {
            set $origin "$http_origin";
        }
        if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' "$origin";
            add_header 'Access-Control-Allow-Credentials' "true";
            add_header 'Access-Control-Max-Age' 86400;
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers' 'DNT,web-token,app-token,Authorization,Accept,Origin,Keep-Alive,User-Agent,X-Mx-ReqToken,X-Data-Type,X-Auth-Token,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
            add_header 'Content-Length' 0;
            add_header 'Content-Type' 'text/plain, charset=utf-8';
            return 204;
        }
        proxy_pass http://xxx_gateway;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_next_upstream http_502 http_504 error timeout invalid_header;
    }

    access_log  /var/log/xxx_gateway.log;
}

  

posted @ 2019-08-20 17:47  宋发准  阅读(372)  评论(0编辑  收藏  举报