upload_img_filter.prod.conf 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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]+)\.(.*) /data/ak-upload-server/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 /data/ak-upload-server/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 ^~ /image-resize {
  32. #rewrite /(image-resize)/(.*) /$2 break;
  33. alias $rule_root/;
  34. image_filter resize $arg_width $arg_height;
  35. image_filter_jpeg_quality 75;
  36. image_filter_buffer 20m;
  37. #allow 127.0.0.0/8;
  38. #deny all;
  39. }
  40. location ^~ /image-crop {
  41. #rewrite /(image-crop)/(.*) /$2 break;
  42. alias $rule_root/;
  43. image_filter crop $arg_width $arg_height;
  44. image_filter_jpeg_quality 75;
  45. image_filter_buffer 20m;
  46. #allow 127.0.0.0/8;
  47. #deny all;
  48. }