将URL映射到文件系统

将此URL映射到此文件系统path的最佳方法是什么?

http://site.com/200x300/ed3269d0-f9ef-4ffc-abea-5982969876c0/my file.jpg 

 /var/www/e/d/3/ed3269d0-f9ef-4ffc-abea-5982969876c0/200x300.jpg 

哪里

  • “200×300”是图像的大小
  • “ed3269d0-f9ef-4ffc-abea-5982969876c0”是图像的guid
  • “我的文件”是文件的名称(用于SEO,可能包含空格)
  • “e”,“d”和“3”是guid的前3个字母
  • “.jpg”是该文件的扩展名

尝试如下所示:

 location / { location ~* ^/(\d+x\d+)/((\w)(\w)(\w)[-\w]+)/[^/]+\.jpg$ { alias /var/www/$3/$4/$5/$2/$1.jpg; } } location /some_other_location/ { ... } 

这就是我所提出的(因为我需要提取扩展名):

 server { root /var/www; location ~* ^/(\d+x\d+)/((\w)(\w)(\w)[-\w]+)/[^\.]+\.(\w+)$ { try_files /$3/$4/$5/$2/$1.$6 /index.html; } }