"set"指令不允许在这里使用。

我正在尝试按照这个示例进行操作- https://gist.github.com/morhekil/1ff0e902ed4de2adcb7a#file-nginx-conf,但是出现错误- "set" directive is not allowed here

我做错了什么?请注意,我正在使用openresty,并将nginx调用为-

nginx -p `pwd`/ -c conf/nginx.conf

我的nginx.conf的上下文与https://gist.github.com/morhekil/1ff0e902ed4de2adcb7a#file-nginx-conf完全匹配

如果我将set变量移动到server部分,我就不再遇到那个错误,但是会出现新的错误-

nginx: [emerg] unknown "resp_body" variable
点赞
用户3765109
用户3765109

经过几个月的等待,终于有了答案 :)

Github 的配置文件似乎有误。在 serverlocationif 块中使用了 set 指令。

语法:set $variable value;

默认值:没有

上下文:server,location,if

http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#set

祝好运!

2015-05-30 19:38:50
用户1244597
用户1244597

我需要一个变量在[全局]设置一次,而且它的值可以在每个服务器块中访问。map指令可以满足我的需求,例如:

map $host $path_to_trunk {
  default "/Users/ruter/Sites/example.co/trunk";
}

使用上述map块,我可以在每个服务器块中访问到$path_to_trunk,例如:

server {
    server_name www.example.local;
    root ${path_to_trunk}/www;
}

server {
    server_name cdn.example.local;
    root ${path_to_trunk}/www/images/content;
}
2021-09-19 17:12:18