nginx配置允许指定域名跨域请求

moonjerx
2021-12-02 / 0 评论 / 114 阅读 / 正在检测是否收录...
set $flag '0';
if ( $http_origin ~* ^(http?:\/\/.*\.changyou\.com:8014$) ){
     set $flag '1';
}
if ( $http_origin ~* ^(http?:\/\/.*\.cy\.com:8014$) ){
     set $flag '1';
}
if ($flag = '1') {
     add_header 'Access-Control-Allow-Origin' $http_origin;
     add_header 'Access-Control-Allow-Credentials' 'true';
     add_header 'Access-Control-Allow-Methods' 'GET,POST';
}
    add_header Access-Control-Allow-Origin *;
    add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
    add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
0

评论 (0)

取消

您的IP: