set $access_control_allow_origin "www.changyy.org";
if ($http_host ~ ^(.*\.changyy\.org)$ ) {
set $access_control_allow_origin $1;
}
if ($http_referer ~ ^(https*\:\/\/.*\.changyy\.org)\/ ) {
set $access_control_allow_origin $1;
}
add_header Access-Control-Allow-Origin $access_control_allow_origin;
add_header Access-Control-Allow-Methods "GET, OPTIONS, POST, HEAD, DELETE, PUT";
add_header Access-Control-Allow-Headers "Authorization, X-Requested-With, Content-Type, Origin, Accept";
add_header Access-Control-Allow-Credentials "true";
add_header Access-Control-Max-Age: 86400;
如此一來,只要是 *.changyy.org 的都可以支援啦!同理就可以用在多網域得設置。
若需要支援不同網域以及非預設的 web port ,則要把規則改成:
set $access_control_allow_origin "www.changyy.org";
if ($http_host ~ ^(.*\.changyy\.org(:[0-9]+)*)$ ) {
set $access_control_allow_origin $1;
}
if ($http_referer ~ ^(https*\:\/\/.*\.changyy\.org(:[0-9]+)*)\/ ) {
set $access_control_allow_origin $1;
}
沒有留言:
張貼留言