nginx 映射配置中反斜杠的用途

Purpose of backslash in nginx map configuration

我正在使用地图配置通过 nginx + fail2ban 来阻止 IP 地址

fail2ban repo 中的 sample configuration 生成器代码如下所示:

...
_echo_blck_row = printf '\%%s 1;\n' "<fid>"
actionban = %(_echo_blck_row)s >> '%(blck_lst_file)s'; %(blck_lst_reload)s
...

注意 \%%s 1;\n 中的前导反斜杠。它创建一个文件,其中的 IP 地址在每个 IP 地址之前都有一个前导反斜杠,即它转储这样的文件

7.0.0.1    1;

而不是简单地

127.0.0.1    1;

两种配置都是正确的。此文件中 IP 地址开头的反斜杠的用途是什么?

来自manual page

If a source value matches one of the names of special parameters described below, it should be prefixed with the “\” symbol.

因此对于 127.0.0.1 这样的值是不必要的(但无害),但它可以防止使用主机名,例如 defaulthostnamesvolatileinclude,它们被认为是 map 块中的“特殊参数”。