Answer the question
In order to leave comments, you need to log in
How to overwrite filename in subfolder for Nginx?
There is the following folder structure
/uploads/2/7/72.jpg -> test.com/uploads/72.jpg
/uploads/3/7/73.jpg -> test.com/uploads/73.jpg
/uploads/4 /7/74.jpg -> test.com/uploads/74.jpg
....
made
location location /uploads/ {
root v:/test/wwwroot;
# rewrite ^/uploads\/([0-9]*)([0-9])([0-9]).(jpe?g|png|gif|webm|bmp|tiff)$ $uri/$3 /$2/$1$2$3.$4 break;
try_files $uri $uri/$3/$2/$1$2$3.$4;
}
And unfortunately it doesn't work, I've tried almost everything. How to properly describe this pattern
2019/10/08 08:22:30 [error] 30528#26804: *63 rewrite or internal redirection cycle while internally redirecting to "/uploads/72.jpg///.///.///./// .///.///.///.///.///.///.///.", client: 127.0.0.1, server: img.test.com, request: "GET / uploads/72.jpg HTTP/1.1", host: "img.test.com"
Answer the question
In order to leave comments, you need to log in
The call code says nothing. Look in devtools where what indents and styles are entered.
The main idea was to store files in subfolders and have short names.
Arranges the backend into folders, the last and penultimate digit of the identifier in the database is used as a key.
uploads\2\4\242.jpg -> img.localhost/242.jpg
uploads\3\4\243.jpg -> img.localhost/243.jpg
The reason is that there would not be a bunch of files in the folder after the upload.
##########################
server {
listen 80;
listen [::]:80;
server_name img.localhost;
charset utf-8;
# Расположение логов
access_log logs/img_localhost_access.log combined;
error_log logs/img_localhost_error.log;
location / {
try_files $uri $uri/ @upfiles;
limit_except GET {
deny all;
}
expires max;
}
location @upfiles {
root v:/project/localhost/localhost/wwwroot/uploads;
rewrite ^(/)([0-9]+)([0-9])([0-9])(.jpe?g|.png|.gif|.webm|.bmp|.tiff)$ /$4/$3/$2$3$4$5 last;
}
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question