2

When I write the location in, it works, when I use the same location as a rewrite rule, it doesnt!!! I dont understand the logic. Can someone please explain?

   location /v3/ {
            alias /var/www/api/v3/html/;
            echo $document_uri;
            echo $document_root;
            echo $request_filename;
            echo $request_uri;
            echo $fastcgi_script_name;
   }

When I do the above, I get

/v3/info.php
/var/www/api/v3/html/
/var/www/api/v3/html/info.php
/v3/info.php
/v3/info.php

But if I now change the location to use rewrite:

   location ~ ^/(v\d+)/ {
            alias /var/www/api/$1/html/;
            echo $document_uri;
            echo $document_root;
            echo $request_filename;
            echo $request_uri;
            echo $fastcgi_script_name;
   }

The paths all get screwed:

/v3/info.php
/var/www/api/v3/html/
/var/www/api/v3/html/
/v3/info.php
/v3/info.php

How come??

3

From the nginx ticket #657:

That's expected behaviour. In a location defined by a regular expression alias defines full path, so you have to use:

location ~ ^/(v\d+)/(.*) {
    alias /var/www/api/$1/html/$2;
    return 200 "request_filename: $request_filename";
}
| improve this answer | |
  • I've come across so many other differences since then that I've learnt to work with it than how i would expect it to work :) – Christian Nov 5 '14 at 22:02
  • Ticket opened... and closed: trac.nginx.org/nginx/ticket/657 I edited my answer to reflect nginx team's – Bernard Rosset Nov 6 '14 at 15:16

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.