大网数据广告活动
服务器运维问答

In a nginx configuration file, how to define a fastcgi_param that contains the "$" sign?

· 52CE 我爱测

I'm trying to define a few environment variables for a PHP application but one of these variables contains the "$" sign. When I test the configuration file with nginx -t , I get an error message telling me that a variable does no…

问题原文

原帖链接 · kant312 · CC BY-SA 3.0

I'm trying to define a few environment variables for a PHP application but one of these variables contains the "$" sign. When I test the configuration file with nginx -t, I get an error message telling me that a variable does not exist. It seems to interpret the text after "$" as a variable name, which is of course not defined.

Maybe I did not search in the right places, but I couldn't find information about how to escape the "$" character. Is that possible and how can it be done?

Update: I tried to enclose the value between single quotes and double quotes following d3ag0s's comment but I had the same error message.

社区高分解答

原帖链接 · kant312 · CC BY-SA 3.0

According to this page, it is not possible to escape the $ sign, but they provide a workaround:

https://openresty.org/download/agentzh-nginx-tutorials-en.html#nginx-variables-escaping-dollar

geo $dollar {
    default "$";
}

server {
    listen 8080;

    location /test {
        echo "This is a dollar sign: $dollar";
    }
}

Although it might not be the best solution, I have tested it and it works.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-06-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。