LoginSignup
17
19

More than 5 years have passed since last update.

nginx に CORS用 の設定をする(複数ドメイン編)

Posted at

nginx に CORS用 の設定をする(複数ドメイン編)
以下のドメインを許可

  • *.example.net
  • *.example.jp
server {
    listen      80;
    server_name hoge.example.com;

    location / {
        if ($http_origin ~* (https?://.*\.example\.(net|jp)?$)) {
            set $cors "1";
        }

        if ($cors = "1") {
            add_header Access-Control-Allow-Origin $http_origin always;
            add_header Access-Control-Allow-Headers 'Authorization,Content-Type,Accept,Origin,User-Agent,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since';
            add_header Access-Control-Allow-Methods 'POST, GET, OPTIONS';
            add_header Access-Control-Allow-Headers 'Origin, Authorization, Accept';
            add_header Access-Control-Allow-Credentials true;
        }
    }
}

参考

Nginx に CORS 用の設定をする。
http://qiita.com/rysk92/items/e5cf2fab8531f8ea3683

17
19
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
17
19