Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

跨域的问题:nginx 应该怎么设置呢?我已经给出了最宽松权限。 #789

Open
buerkingkong opened this issue Mar 7, 2024 · 1 comment

Comments

@buerkingkong
Copy link

`
location / {
autoindex on; # 启用目录索引
try_files $uri $uri/ =404;

    # 无条件添加 CORS 头部,允许所有请求
    add_header 'Access-Control-Allow-Origin' '*';
    add_header 'Access-Control-Allow-Methods' '*';
    add_header 'Access-Control-Allow-Headers' '*';
    add_header 'Access-Control-Max-Age' 1728000;

    # 预检请求的特殊处理
    if ($request_method = 'OPTIONS') {
        add_header 'Content-Type' 'text/plain; charset=utf-8';
        add_header 'Content-Length' 0;
        return 204;
    }
}

`

@xyxiao001
Copy link
Owner

xyxiao001 commented Mar 7, 2024

location ~* \.(gif|jpg|jpeg|png|bmp|swf)$ {
  add_header Access-Control-Allow-Origin *;
  add_header Access-Control-Allow-Headers X-Requested-With;
  add_header Access-Control-Allow-Methods GET,POST,OPTIONS;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants