nginx HttpEchoModule允许我访问单个nginx变量:
location /whathost {
echo "This host is $http_host";
}
我想看到每个可用的变量及其值,类似于bash中set
(w/o args)的输出。
这可能吗?
nginx HttpEchoModule允许我访问单个nginx变量:
location /whathost {
echo "This host is $http_host";
}
我想看到每个可用的变量及其值,类似于bash中set
(w/o args)的输出。
这可能吗?
2条答案
按热度按时间r9f1avp51#
我不认为有一个内置的方式来显示所有的变量。但如果你看看源代码,他们似乎是定义在:src/http/ngx_http_variables.c
查找
ngx_string
,下面是一些awk来打印它们:awk -F\" '/[^\w]ngx_string[^\w]/ {printf "%s:\t$%s\n", $2, $2}' src/http/ngx_http_variables.c
然后你就可以编写自己的set函数了:
你可以在这里找到来源:http://hg.nginx.org/nginx
或者你可以看到我在这里找到的变量:http://pastie.org/9992530
brccelvz2#
下面是我用来显示nginx documentation here中的变量列表的代码片段。我不得不删除一些变量,因为它们在我的设置中不可用,因为它们来自不同的模块,我没有默认启用它们。我使用了官方docker hub page中的默认nginx映像。
这肯定不是一个完整的变量列表,因为不同的模块和不同版本的nginx可能会提供不同的变量。不幸的是,我不知道任何编程的方式,我们可以用来迭代所有可能的变量列表。