在我的 nginx 配置中 $http_origin 是空字符串

In my nginx config $http_origin is empty string

我什至尝试过一些愚蠢的事情:

add_header 'Access-Control-Allow-Origin' "http://loca${http_origin}lhost:3000";

结果只是 http://localhost:3000,所以它是空的。为什么?

I don't think browser will send a request with a header called "Origin". So your nginx can't get $http_origin

$http_origin 意思是 "Get request's header: Origin"

你可以试试这个:

curl localhost:3000 -H "origin: google.com"

$http_xxx 变量是请求的 headers

参考:https://nginx.org/en/docs/http/ngx_http_core_module.html#var_http_