With NGiNX I get a string that contains information that I can extract content with regex.

But the only way I found that I could do this, is with if block. Is there any another way?

The extracted value needs to be set in a variable.


You can catch content to variable with PCRE named capture. It is well described in the official Nginx doc.

  • That's for when you use server_name. I am trying to catch the value found in a string that as nothing to do with the domain name and is found in the location block.
    – jnbdz
    May 20 '13 at 5:20
  • No, it's not. Try such config: location ~ ^/foobar/(?<somenumbers>\d+) { return 200 "New link will be: somecoolsite.com/$somenumbers.jpeg\n"; default_type text/plain; } May 20 '13 at 10:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.