Nginx post 请求似乎正在删除我的 header ,那么如何才能让 header “Access-Control-Allow-Origin”保留在 post 请求上?
location /api {
proxy_pass http://127.0.0.1:3567/;
if ($request_method = OPTIONS) {
add_header "Access-Control-Allow-Origin" "http://localhost:8080";
add_header "Access-Control-Allow-Methods" "GET, POST, OPTIONS";
add_header "Content-Type" "text/plain";
add_header "Access-Control-Allow-Credentials" "true";
add_header "Access-Control-Allow-Headers" "content-type,rid,fdi-version";
add_header "Content-Length" 0;
return 204;
}
add_header "Access-Control-Allow-Origin" "http://localhost:8080";
}
目前,当请求方法设置为 OPTIONS 时,它可以工作,但不适用于 POST 请求。我希望我的响应中会有标题“Access-Control-Allow-Origin”,但没有
最佳答案
您的 POST 请求是否有可能返回错误响应?如果是这样改变
add_header "Access-Control-Allow-Origin" "http://localhost:8080";
至
add_header "Access-Control-Allow-Origin" "http://localhost:8080" always;
关于nginx - 设置 nginx post 请求的响应 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74284436/