设置nginx post请求的响应标头

jaxagkaj  于 2023-01-04  发布在  Nginx
关注(0)|答案(1)|浏览(156)

Nginx post请求似乎正在删除我的头文件,那么我如何才能让头文件“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";
    }

现在,当request方法设置为OPTIONS时,它可以工作,但对于POST请求则不行。我希望在响应中有“Access-Control-Allow-Origin”头,但是没有

mwkjh3gx

mwkjh3gx1#

你的POST请求是否会返回错误响应?如果是,请更改

add_header "Access-Control-Allow-Origin" "http://localhost:8080";

add_header "Access-Control-Allow-Origin" "http://localhost:8080" always;

相关问题