nginx跨域(网上找的)

Posted songfahzun

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;

  

以上是关于nginx跨域(网上找的)的主要内容,如果未能解决你的问题,请参考以下文章

nginx跨域设置

使用Nginx来解决跨域的问题

Nginx前后端跨域

Nginx前后端跨域

Nginx前后端跨域

vue3.0+nginx跨域问题