nginx允许跨域的设置

星野梦璃
2024-05-16 / 0 评论 / 82 阅读
    location / {# /可以改为路径 例如/test/img
      # 允许所有以 mmix.cc 结尾的域名访问资源
      if ($http_origin ~* "^https?://[a-zA-Z0-9_-]+\.yyfj\.cc(:[0-9]+)?$") {

          add_header 'Access-Control-Allow-Origin' "$http_origin";
          add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
          add_header 'Access-Control-Allow-Headers' 'Content-Type';
          add_header 'Access-Control-Allow-Credentials' 'true';
      }

    # 其他 Nginx 配置项...
    }
0

评论 (0)

取消