Map指令内的变量插值 [英] Variable interpolation inside Map directive
本文介绍了Map指令内的变量插值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在Nginx的http指令内映射一个变量.
I am trying to map a variable inside the http directive in Nginx.
当单独放置时,变量将单独扩展,如果我在字符串中添加其他内容,扩展将停止工作.
When left alone, the variable alone gets expanded, if I add anything else to the string the expansion stops working.
http {
map $host $foo {
#default "$host"; # - this works fine and returns 'localhost'
default "This is my host: $host"; # - THIS DOESN'T WORK
}
server {
location / {
echo $foo;
}
}
}
您对在地图内部进行扩展有什么建议吗?
Do you have any suggestions to make the expansion work inside the map?
推荐答案
如map
指令文档:
结果值可以是字符串或其他变量(0.9.0).
The resulting value can be a string or another variable (0.9.0).
更新:此功能已添加到NGinx的1.11.2版本中,如此处的注释7:
Update: This functionality has been added to version 1.11.2 of NGinx, as per Comment #7 here: https://trac.nginx.org/nginx/ticket/663#comment:7
这篇关于Map指令内的变量插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文