upload_img_filter.dev.conf 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. set $rule_root $document_root;
  2. location ~* /files/(.*)/(.*)\/([0-9a-z]+)\.(jpg|png|jpeg|gif)@(\d+)x(\d+)Q_([rc])$ {
  3. if (-f $request_filename) {
  4. break;
  5. }
  6. set $filepath "files/$1/$2";
  7. set $filename "$3.$4";
  8. set $thumb "$3_$5x$6.$4";
  9. set $width $5;
  10. set $height $6;
  11. set $type $7;
  12. if ( $type = 'r' ){
  13. set $type 'image-resize'; #旋转
  14. }
  15. if ( $type = 'c' ){
  16. set $type 'image-crop'; #剪切
  17. }
  18. if (!-f $document_root/$filepath/$filename) {
  19. return 404;
  20. }
  21. rewrite /files/(.*)/(.*)\/([0-9a-z]+)\.(.*) /imgcache/$1/$2/$thumb;
  22. if (!-f $request_filename) {
  23. proxy_pass $scheme://127.0.0.1:$server_port/$type/$filepath/$filename?width=$width&height=$height;
  24. break;
  25. }
  26. #proxy_store $document_root/imgcache/$1/$2/$thumb;
  27. #proxy_store_access user:rw group:rw all:r;
  28. proxy_set_header Host $host;
  29. expires 10d; # 设置图片过期时间10天
  30. }
  31. location ~* /attachment/(.*)/(.*)\/([0-9a-z]+)\.(jpg|png|jpeg|gif)@(\d+)x(\d+)Q_([rc])$ {
  32. if (-f $request_filename) {
  33. break;
  34. }
  35. set $filepath "attachment/$1/$2";
  36. set $filename "$3.$4";
  37. set $thumb "$3_$5x$6.$4";
  38. set $width $5;
  39. set $height $6;
  40. set $type $7;
  41. if ( $type = 'r' ){
  42. set $type 'image-resize'; #旋转
  43. }
  44. if ( $type = 'c' ){
  45. set $type 'image-crop'; #剪切
  46. }
  47. if (!-f $document_root/$filepath/$filename) {
  48. return 404;
  49. }
  50. rewrite /attachment/(.*)/(.*)\/([0-9a-z]+)\.(.*) /imgcache/$1/$2/$thumb;
  51. if (!-f $request_filename) {
  52. proxy_pass $scheme://127.0.0.1:$server_port/$type/$filepath/$filename?width=$width&height=$height;
  53. break;
  54. }
  55. #proxy_store $document_root/imgcache/$1/$2/$thumb;
  56. #proxy_store_access user:rw group:rw all:r;
  57. proxy_set_header Host $host;
  58. expires 10d; # 设置图片过期时间10天
  59. }
  60. location ^~ /image-resize {
  61. #rewrite /(image-resize)/(.*) /$2 break;
  62. alias $rule_root/;
  63. image_filter resize $arg_width $arg_height;
  64. image_filter_jpeg_quality 75;
  65. image_filter_buffer 20m;
  66. #allow 127.0.0.0/8;
  67. #deny all;
  68. }
  69. location ^~ /image-crop {
  70. #rewrite /(image-crop)/(.*) /$2 break;
  71. alias $rule_root/;
  72. image_filter crop $arg_width $arg_height;
  73. image_filter_jpeg_quality 75;
  74. image_filter_buffer 20m;
  75. #allow 127.0.0.0/8;
  76. #deny all;
  77. }