Skip to main content

解决nginx跨域#Script location / {

  1. 解决nginx跨域
    #Script

            location / {
                # 允许所有源
                if ($request_method = 'OPTIONS') {
                    add_header 'Access-Control-Allow-Origin' '*';
                    add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, DELETE, PUT';
                    add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
                    add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
                    add_header 'Access-Control-Max-Age' 1728000;
                    add_header 'Content-Type' 'text/plain charset=UTF-8';
                    add_header 'Content-Length' 0;
                    return 204;
                }
    
                if ($request_method = 'GET') {
                    add_header 'Access-Control-Allow-Origin' '*';
                }
    
                # 其他配置
                proxy_pass http://your_upstream_server;
            }
OKHK