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 跨域 #55

Open
tjlizz opened this issue Mar 28, 2024 · 0 comments
Open

Nginx 跨域 #55

tjlizz opened this issue Mar 28, 2024 · 0 comments

Comments

@tjlizz
Copy link
Owner

tjlizz commented Mar 28, 2024

指定允许跨域的方法,*代表所有

    add_header Access-Control-Allow-Methods *;

    #   预检命令的缓存,如果不缓存每次会发送两次请求
    add_header Access-Control-Max-Age 3600;
    #   带cookie请求需要加上这个字段,并设置为true
    add_header Access-Control-Allow-Credentials true;

    #   表示允许这个域跨域调用(客户端发送请求的域名和端口) 
    #   $http_origin动态获取请求客户端请求的域   不用*的原因是带cookie的请求不支持*号
    add_header Access-Control-Allow-Origin $http_origin;

    #   表示请求头的字段 动态获取
    add_header Access-Control-Allow-Headers 
    $http_access_control_request_headers;

    #   OPTIONS预检命令,预检命令通过时才发送请求
    #   检查请求的类型是不是预检命令
    if ($request_method = OPTIONS){
        return 200;
    }
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

1 participant