我正在尝试使用nginx的njs模块和子请求将两个请求链接在一起。我可以看到在响应头中返回了special_value,但是我不知道如何使用proxy_set_header来读取值。以下代码将导致X-Special-Value中的值为空值
nginx.conf:
location ~* /step_one {
js_content njs_func;
}
location ~* /step_two {
proxy_pass http://some_other/api;
proxy_set_header X-Special-Value $http_special_val;
}http.js
function njs_func(r) {
r.headersOut['special_val'] = '42';
r.subrequest('/step_two')
.then(reply => r.return(reply.status, reply.responseBody));
}发布于 2021-01-13 04:15:45
你可以这样做:
nginx.conf
set $specialValue "";
location ~* /step_one {
js_content njs_func;
}
location ~* /step_two {
proxy_pass http://some_other/api;
proxy_set_header X-Special-Value $specialValue;
}https.js
function njs_func(r) {
r.variables.specialValue = '42';
r.subrequest('/step_two')
.then(reply => r.return(reply.status, reply.responseBody));
}https://stackoverflow.com/questions/64814598
复制相似问题