"alias" directive may not be used inside location given

Igor Sysoev igor at sysoev.ru
Wed Jul 7 16:39:47 MSD 2010


On Wed, Jul 07, 2010 at 02:32:57PM +0200, Fernando Perez wrote:

> I don't understand the following error:
> 
> the "alias" directive may not be used inside location given by regular
> expression
> 
> >From the docs it seems possible:
> http://wiki.nginx.org/NginxHttpCoreModule#alias
> 
> I'm running 0.7.38

This is possible since 0.7.40.

> Here is my conflictual declaration:
> 
> location ~* ^/uploads/([\w\-\/]+\.(jpg|m4v|mp4|ogv|png)) {
>   alias  $rails_path/uploads/production/$1;
> }
> 
> I want to map the request /uploads/assets/myfile.png to
> /uploads/production/assets/myfile.png on disk

In this case you do not need regex:

location  /uploads/ {
   alias  $rails_path/uploads/production/;
}

BTW, it's better to not use "set $rails_path /rails;",
but set it in alias:

location  /uploads/ {
   alias  /rails/uploads/production/;
}


-- 
Igor Sysoev
http://sysoev.ru/en/



More information about the nginx mailing list