Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The location from nginx conf:

location ~/photos/resize/(\d+)/(\d+) {
    # Here var1=(\d+), var2=(\d+)

How to I get variables from location in nginx?

share|improve this question
up vote 8 down vote accepted

The regex works pretty much like in every other place that has it.

location ~/photos/resize/(\d+)/(\d+) {
  # use $1 for the first \d+ and $2 for the second, and so on.

Looking at examples on the nginx wiki may also help,

share|improve this answer

In addition to the previous answers, you can also set the names of the regex captured groups so they would easier to be referred later;

location ~/photos/resize/(?<width>(\d+))/(?<height>(\d+)) {
  # so here you can use the $width and the $height variables

see NGINX: check whether $remote_user equals to the first part of the location for an example of usage.

share|improve this answer

You may try this:

location ~ ^/photos/resize/.+ {
    rewrite ^/photos/resize/(\d+)/(\d+) /my_resize_script.php?w=$1&h=$2 last;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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