【问题标题】:"set" directive is not allowed here此处不允许使用“set”指令
【发布时间】:2015-01-08 14:07:11
【问题描述】:

我在这里尝试遵循此示例-https://gist.github.com/morhekil/1ff0e902ed4de2adcb7a#file-nginx-conf 但出现错误-"set" directive is not allowed here

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

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

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

如果我将 set 变量移动到服务器部分,我将不再收到该错误,而是一个新错误-

nginx: [emerg] unknown "resp_body" variable

【问题讨论】:

    标签: variables nginx configuration


    【解决方案1】:

    几个月后,答案即将到来:)

    Github 配置文件似乎错误。 set 指令用于 serverlocationif 块。

    语法:设置$变量值;
    默认值:-
    上下文:服务器,位置,如果

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

    祝你好运!

    【讨论】:

    【解决方案2】:

    我需要一个变量[全局]设置一次,并且它的值可以在每个服务器块中访问。 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;
    }
    

    【讨论】:

      猜你喜欢
      • 2014-10-08
      • 2019-03-16
      • 1970-01-01
      • 2018-05-15
      • 2023-03-04
      • 2014-05-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多