Extracting matches in NGiNX with regex without if block

14,253

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

Share:
14,253
jnbdz
Author by

jnbdz

Updated on September 18, 2022

Comments

  • jnbdz
    jnbdz 10 months

    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.

  • jnbdz
    jnbdz about 10 years
    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.
  • Max Kochubey
    Max Kochubey about 10 years
    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; }