在你提供的配置中,存在一个语法错误。在第6行的 add_header Access-Control-Allow-Headers '*'
以及第16行的 add_header 'Content-Length'0;
中缺少了分号(;)。
此外,在第14行缺少了一个分号(;),应该修改为 add_header Access-Control-Allow-Headers 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
修改后的代码如下:
location ^~ /api/ {
proxy_pass http://127.0.0.1:8100/api/;
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';
add_header 'Access-Control-Allow-Headers' '*';
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Origin' $http_origin;
add_header 'Access-Control-Allow-Methods' 'GET,POST,OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain;charset=utf-8';
add_header 'Content-Length' 0;
return 204;
}
}
请注意,根据你的具体需求和Nginx版本,可能需要进一步调整和测试这些配置。确保你的Nginx配置文件符合语法要求,并使用 nginx -t
命令进行测试,以确保没有其他语法错误或冲突。
内容由零声教学AI助手提供,问题来源于学员提问