【发布时间】:2013-05-06 05:17:17
【问题描述】:
使用此配置:
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 子句中?
【问题讨论】:
-
请不要交叉发帖。 serverfault.com/questions/506972/…
-
我开了一个聊天室来讨论这个问题。我们可以在那里继续讨论。 chat.stackexchange.com/rooms/8745/nginx
标签: configuration nginx proxy