国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網(wǎng)站 > Nginx > 正文

Nginx生成縮略圖并存儲(chǔ)到硬盤上

2024-08-30 12:26:12
字體:
供稿:網(wǎng)友

現(xiàn)在隨著各終端的出現(xiàn)(手機(jī),ipad等平板),以及各種終端的手機(jī)分辨率和尺寸都不同,現(xiàn)在手機(jī)用戶流量都是寶,網(wǎng)上出現(xiàn)了各種各樣的生成縮略圖功能的架構(gòu),有使用php實(shí)時(shí)生成縮略圖的,也有用nginx + lua實(shí)現(xiàn)的,上節(jié)我也講到了使用nginx生成縮略圖,但是用戶每次訪問都需要生成一次,會(huì)給cpu和硬盤帶來比較大的壓力,今天帶來了另外一種方式,這次使用nginx將原圖生成縮略圖到硬盤上.看我的配置

1、首先創(chuàng)建好cache目錄

[root@masterserver ~]# mkdir -p /data/stie_cache [root@masterserver ~]# 

2、修改nginx配置,增加如下內(nèi)容

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;}

完整的nginx配置文件如下:

[root@masterserver conf]# cat nginx.confworker_processes 1;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;server {listen 80;server_name localhost;location / {root html;index index.html index.htm;image on;image_output on;}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;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}}[root@masterserver conf]# 

提示:

nginx編譯的時(shí)候要添加參數(shù)--with-http_image_filter_module,保險(xiǎn)起見將模塊ngx_image_thumb-master也帶上,所以最終nginx編譯參數(shù)為:

./configure --add-module=../ngx_image_thumb-master/ --with-http_image_filter_module

生成縮略圖流程如下:

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 靖安县| 东乡县| 卫辉市| 荣成市| 科技| 铁岭县| 盐池县| 巧家县| 景宁| 宁波市| 宁城县| 汝南县| 巴马| 大新县| 株洲市| 六枝特区| 陈巴尔虎旗| 茌平县| 胶南市| 平遥县| 新晃| 鄂尔多斯市| 承德市| 青川县| 锦州市| 黑河市| 开江县| 泸溪县| 册亨县| 涞源县| 阳江市| 唐河县| 嘉黎县| 德令哈市| 克东县| 精河县| 白河县| 陆河县| 八宿县| 鄂尔多斯市| 工布江达县|