使用此配置:
server {
listen 8080;
location / {
if ($http_cookie ~* "mycookie") {
proxy_set_header X-Request $request;
proxy_pass http://localhost:8081;
}
}
}
重新加载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
此配置可以正常运行,但不能满足我的要求:
server {
listen 8080;
location / {
proxy_set_header X-Request $request;
if ($http_cookie ~* "mycookie") {
proxy_pass http://localhost:8081;
}
}
}
为什么我不能将proxy_set_header指令放在if子句中?
请不要交叉发布。stackoverflow.com/questions/16500594/…–
—
ceejayoz
我打开了一个聊天讨论此事。我们可以在那继续讨论:chat.stackexchange.com/rooms/8745/nginx
—
Neuquino 2013年