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

nginx跨域(网上找的)

时间:2019-08-20 18:50:42      阅读:65      评论:0      收藏:0      [点我收藏+]

标签:token   invalid   cache   ken   accept   range   option   host   for   

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

  

nginx跨域(网上找的)

标签:token   invalid   cache   ken   accept   range   option   host   for   

原文地址:https://www.cnblogs.com/songfahzun/p/11384488.html

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