如今隨着各終端的出現(手機,ipad等平板),以及各類終端的手機分辨率和尺寸都不一樣,如今手機用戶流量都是寶,網上出現了各類各樣的生成縮略圖功能的架構,有使用php實時生成縮略圖的,也有用nginx + lua實現的,上節我也講到了使用nginx生成縮略圖,可是用戶每次訪問都須要生成一次,會給cpu和硬盤帶來比較大的壓力,今天帶來了另一種方式,此次使用nginx將原圖生成縮略圖到硬盤上.看個人配置 php
1. 首先建好cache目錄 html
1
|
# mkdir /data/site_cache/
|
2. 修改nginx配置 nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
location ~* ^/resize{
root/data/site_cache/$server_name;
set$width 150;
set$height 100;
set$dimens"";
if($uri ~*"^/resize_(\d+)x(\d+)/(.*)") {
set$width $1;
set$height $2;
set$image_path $3;
set$demins"_$1x$2";
}
if($uri ~*"^/resize/(.*)") {
set$image_path $1;
}
set$image_uri image_resize/$image_path?width=$width&height=$height;
if(!-f $request_filename) {
proxy_pass http://127.0.0.1/$image_uri;
break;
}
proxy_store/data/site_cache/$server_name/resize$demins/$image_path;
proxy_store_access user:rw group:rw all:r;
proxy_set_header Host $host;
expires 30d;
access_log off;
}
location/image_resize{
alias/data/site/$server_name/;
image_filter resize $arg_width $arg_height;
image_filter_jpeg_quality 75;
access_log off;
}
|