Php+nginx makes a picture server

use 117773ee38db401fcec7e4ff2d6008263c1593b14c.jpg on a website http://img.xxx.com/aabbccdd38., which I expect to put in the / data/www/aa/bb/cc/ folder, means to take three two or two groups as subdirectories according to the file name, and then store the files.

Mar.21,2021

just set the root directory of sever in nginx to / data/www/11/77/3e/


nginxserver/data/www/,php,mkdir -p ./11/aa/bb

,nginx
:https://img.codeshelper.com/upload/img/2021/03/21/13m0yjdqmga11581.jpg
/data/www/11/aa/bb/11aabbee38db401fcec7e4ff2d6008263c1593b14c.jpg
nginx
server {
    listen 80;
    server_name  img.xxx.com;
    root   /data/www;
    
    charset utf-8;
    
    access_log  logs/host.access.log  main;
     
    location ~ .*\\.(gif|jpg|jpeg|bmp|png|ico|txt|js|css)$   
    {  
        rewrite ^([a-z0-9A-z]{2})([a-z0-9A-z]{2})([a-z0-9A-z]{2})(.*) /data/www/$1/$2/$3/$1$2$3$4
    }
}
Menu