跨域配置

location /static/{
            1、允许所有请求
            #add_header 'Access-Control-Allow-Origin' '*' always;
            #add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
            #add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization, X-Requested-With';

            2、资源请求直接回应         

            #autoindex on;
            #alias /home/car_behavior/backend/static/;

            3、静态资源请求转发到本系统
            proxy_pass  http://127.0.0.1:18093/static/;

           

           
        }

方案一是启用1和2,nginx会直接回应请求,要什么给什么

方案二,注释1和2,自定义跨域处理

我选择的方案二,对跨域的请求做了一些限制和处理

更多推荐