5

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
  • 201
  • 2
  • 7

1 Answers1

5

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.

kant312
  • 201
  • 2
  • 7
  • OMG this is a f--king terrible 'solution'. I have to define a variable in a file completely separate from my fastcgi_params file to get it in my fastcgi_params file? How do you even pass this off from nginx to FPM? – tpartee Jan 08 '20 at 18:31
  • 1
    @tpartee good day to you too. I don't understand your comment, because you don't need to declare the variable in a separate file, I certainly did not. You can pass a variable from nginx to FPM with: `fastcgi_param VAR_NAME value;` – kant312 Jan 09 '20 at 08:56