Access-Control-Allow-Origin Multiple Origin Domains?

前端 未结 30 2066
隐瞒了意图╮
隐瞒了意图╮ 2020-11-21 07:08

Is there a way to allow multiple cross-domains using the Access-Control-Allow-Origin header?

I\'m aware of the *, but it is too open. I rea

30条回答
  •  无人及你
    2020-11-21 07:37

    As mentioned above, Access-Control-Allow-Origin should be unique and Vary should be set to Origin if you are behind a CDN (Content Delivery Network).

    Relevant part of my Nginx configuration:

    if ($http_origin ~* (https?://.*\.mydomain.example(:[0-9]+)?)) {
      set $cors "true";
    }
    if ($cors = "true") {
      add_header 'Access-Control-Allow-Origin' "$http_origin";
      add_header 'X-Frame-Options' "ALLOW FROM $http_origin";
      add_header 'Access-Control-Allow-Credentials' 'true';
      add_header 'Vary' 'Origin';
    }
    

提交回复
热议问题