Neu*_*ino 10 configuration proxy nginx
使用此配置:
server {
listen 8080;
location / {
if ($http_cookie ~* "mycookie") {
proxy_set_header X-Request $request;
proxy_pass http://localhost:8081;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我重新加载nginx服务时出现此错误:
Reloading nginx configuration: nginx: [emerg] "proxy_set_header" directive is not allowed here in /etc/nginx/conf.d/check_cookie.conf:5
nginx: configuration file /etc/nginx/nginx.conf test failed
Run Code Online (Sandbox Code Playgroud)
这个配置工作正常,但它没有做我想要的:
server {
listen 8080;
location / {
proxy_set_header X-Request $request;
if ($http_cookie ~* "mycookie") {
proxy_pass http://localhost:8081;
}
}
}
Run Code Online (Sandbox Code Playgroud)
为什么我不能将proxy_set_header指令放在if子句中?
小智 7
内部位置尝试这样的事情
# default header value in a new variable
set $esb "$remote_addr, $host";
# if my custom header exists
if ($http_my_header){
set $esb "$http_my_header, $remote_addr, $host";
}
proxy_set_header my-header $esb;
Run Code Online (Sandbox Code Playgroud)
与 proxy_pass 不同,您不能将 proxy_set_header 放在 if 块内。您只能将其放在 http/server/location 块中。所以你的第二个配置很好。
参考: http: //nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_set_header
上下文:http、服务器、位置
不知道 $request 变量是什么。它没有出现在 nginx 变量列表中:http://wiki.nginx.org/HttpCoreModule#Variables。你想在这里实现什么目标?
| 归档时间: |
|
| 查看次数: |
8627 次 |
| 最近记录: |