nginx配置跨域cors配置

vhost配置

location / {
        add_header Access-Control-Allow-Origin $http_origin;
        add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
        add_header Access-Control-Allow-Credentials true;
        add_header Access-Control-Allow-Headers DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type;
        add_header Access-Control-Max-Age 1728000;
        if ($request_method = OPTIONS) {
              add_header Access-Control-Allow-Origin $http_origin;
              add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
              add_header Access-Control-Allow-Credentials true;
              add_header Access-Control-Allow-Headers DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type;
              add_header Access-Control-Max-Age 1728000;
              return 204;
         }
    }

你可能感兴趣的:(nginx配置跨域cors配置)