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