Welcome! Log In Create A New Profile

Advanced

nginx + rewrite + try_files

Posted by marku5 
nginx + rewrite + try_files
April 20, 2017 09:02AM
Hi,
I use Nginx for a file distribution on a server with a lot of files. Files is requested by URI like http://hostname/files/somefiles/GUID/UID/filename.zip.
Because there is a really tonn of files on server, I use five storage devices, which is mounted on root fs and store files like this:
/mnt/st0/sf/guid/uid/file1.zip
/mnt/st1/sf/guid/uid/file2.zip
/mnt/st2/sf/guid/uid/file3.zip
/mnt/st3/sf/abc/guid/def/uid/file4.zip
/mnt/st4/sf/abc/guid/def/uid/file5.zip
where ABC is a first 3 symbols of GUID and DEF is a first 3 symbols of UID.
At this time I use rewrite + try_files:
---
location /files/somefiles/ {
root /;
rewrite "^/files/somefiles/(.*)$" "/sf/$1" break;
try_files /mnt/st0$uri /mnt/st1$uri /mnt/st2$uri @uri3s;
}
location @uri3s {
root /;
rewrite "^/sf/([A-F0-9]{3})([A-F0-9-]{33}/)([a-f0-9]{3})(.*\.zip)$" "/$1/$1$2/$3/$3$4" break; #GUID lenth is 33 uppercase symbols, UID is always in lowercase.
try_files /mnt/st3/sf$uri /mnt/st4/sf$uri =404;
}
---
All works fine in test envirorment, but on production server with 6k rpm I have LA about 6.
How can I optimize this?
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 301
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready