前后端分离,跨域,nginx中忽略OPTIONS请求配置跨域

2019-11-27  本文已影响0人  没心没肺最开心
现在很多项目都是喜欢前后端分离,网上看了很多感觉心累,写的七七八八,多次尝试后把自己用的展示如下:
          if ($http_origin ~* "^http://a.domain.com$") {
                  set $cors_origin $http_origin;
          }
          if ($http_origin ~* "^http://b.domain.com$") {
                  set $cors_origin $http_origin;
          }
          if ($request_method = 'OPTIONS') {
        add_header Access-Control-Allow-Origin $http_origin;
        add_header Access-Control-Allow-Headers X-Requested-With,aheader, bheader, cheader;
        add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
        add_header Access-Control-Allow-Credentials true;
        add_header Access-Control-Max-Age 86400;
          return 204;

        }
        add_header Access-Control-Allow-Origin $http_origin;
        add_header Access-Control-Allow-Headers X-Requested-With,aheader, bheader, cheader;
        add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
        add_header Access-Control-Allow-Credentials true;
        add_header Access-Control-Max-Age 86400;

注意:

上一篇 下一篇

猜你喜欢

热点阅读