# Help with location and order

**URL:** <https://www.ruby-forum.com/t/help-with-location-and-order/190013>\
**Category:** NGINX\
**Created:** [June 11, 2010, 11:38am UTC](https://www.ruby-forum.com/t/help-with-location-and-order/190013 "2010-06-11T11:38:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ilifeis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e79b87/32.png) [@ilifeis](https://www.ruby-forum.com/u/ilifeis)\
**Post date:** [June 11, 2010, 11:38am UTC](https://www.ruby-forum.com/t/help-with-location-and-order/190013/1 "2010-06-11T11:38:27Z")

</div>

I have this config, I need to use jpg in /data/abc/files/ but when I  
browse it nginx will use file jpg in /var/www/images (second condition),  
how to fix it?

root /var/www/images;

location = /abc/files/ {  
alias /data/abc/files/;  
break;  
}

location ~\* ^.+.(jpg|jpeg|gif|css|png|js|ico|swf|flv)$ {  
access\_log off;  
expires 1d;  
}

---

<div class="post-metadata">

**Author:** ![ilifeis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e79b87/32.png) [@ilifeis](https://www.ruby-forum.com/u/ilifeis)\
**Post date:** [June 11, 2010, 11:46am UTC](https://www.ruby-forum.com/t/help-with-location-and-order/190013/2 "2010-06-11T11:46:45Z")

</div>

On Fri, Jun 11, 2010 at 4:38 PM, Life L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I have this config, I need to use jpg in /data/abc/files/ but when I  
> browse it nginx will use file jpg in /var/www/images (second condition),  
> how to fix it?
> 
> root /var/www/images;
> 
> location = /abc/files/ {

will only match address /abc/files/. Remove =.

> Â Â Â Â alias /data/abc/files/;  
> Â Â Â Â break;  
> }
> 
> location ~\* ^.+.(jpg|jpeg|gif|css|png|js|ico|swf|flv)$ {  
> Â Â Â Â access\_log Â off;  
> Â Â Â Â expires Â Â 1d;  
> }

but any jpg will probably get in here anyway, so I guess using  
location ~\* ^/abc/files/(._)$ {  
alias /data/abs/files/$1;  
}  
is better. Also make sure to put that block above the location ~_  
.(jpg|jpeg|gif|css|png|js|ico|swf|flv)$ { } block.

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://nginx.org/mailman/listinfo/nginx)

–  
O\< ascii ribbon campaign - stop html mail - [www.asciiribbon.org](http://www.asciiribbon.org)

---

<div class="post-metadata">

**Author:** ![ilifeis](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e79b87/32.png) [@ilifeis](https://www.ruby-forum.com/u/ilifeis)\
**Post date:** [June 11, 2010, 12:05pm UTC](https://www.ruby-forum.com/t/help-with-location-and-order/190013/3 "2010-06-11T12:05:29Z")

</div>

On Fri, Jun 11, 2010 at 11:38:27AM +0200, Life L. wrote:

> location ~\* ^.+.(jpg|jpeg|gif|css|png|js|ico|swf|flv)$ {  
> access\_log off;  
> expires 1d;  
> }

1. “break” is useless here and only wastes CPU cycles.
2. you may use “root” instead of “alias”
3. “=” is exact match, but not prefix match.
4. “^~” disables testing regexes, thus

location ^~ /abc/files/ {  
root /data/;  
}

–  
Igor S.

> **[Igor Sysoev](http://sysoev.ru/en/)**
