6

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.

6
  • 1
    Try using quotes for your environment variable that contain special characters. Commented Jun 8, 2017 at 8:41
  • I just did (using ' and ") but unfortunately it does not change the error message. Commented Jun 8, 2017 at 8:44
  • Try setting the variable set $myvar "$environmentvariable" then use $myvar instead Commented Jun 8, 2017 at 9:08
  • I just tried it as well but unfortunately, the value is still being evaluated in the variable assignment. Commented Jun 8, 2017 at 9:22
  • Have you tried \$ ? Commented Jun 8, 2017 at 9:31

1 Answer 1

7

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.

2
  • 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? Commented Jan 8, 2020 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; Commented Jan 9, 2020 at 8:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.