1. 程式人生 > >nginx image_filter 配置記錄

nginx image_filter 配置記錄

nginx_image_filter 

http_image_filter_module
配置

----------------------------------
第一種:

//官方配置
location /img/ {
    proxy_pass   http://backend;
    image_filter resize 150 100;
    image_filter rotate 90;
    error_page   415 = /empty;
}

location = /empty {
    empty_gif;
}

http://nginx.org/en/docs/http/ngx_http_image_filter_module.html#image_filter_webp_quality
----------------------------------- 第二種: //裁剪圖片,不儲存硬碟 訪問 http://xxx.com/[email protected]_100h_75Q_r http://xxx.com/[email protected]_100h_75Q_r http://xxx.com/img/[email protected]_11_h_80Q_r # 等比縮放圖片 location ~ (.+)\.(jpg|gif|png)@(\d+)w_(\d+)h_(\d+)Q_r$ { set $w $3; #寬 set $h $4
; #高 set $q $5; #圖片質量 image_filter resize $w $h; image_filter_jpeg_quality $q; image_filter_buffer 5M; try_files $1.$2 /img/notfound.jpg; } # 裁剪圖片 location ~ (.+)\.(jpg|gif|png)@(\d+)w_(\d+)h_(\d+)Q_c$ { set $w $3; #寬 set $h $4; #高 set $q $5; #圖片質量 image_filter crop $
w $h; image_filter_jpeg_quality $q; image_filter_buffer 5M; try_files $1.$2 /img/notfound.jpg; } --------------------------------------- 第三種: //儲存在磁碟 訪問 http://xxx.com/image_filter/[email protected]_120h_75Q_r 代理到 xxx.com/image-resize/image_filter/222.jpg?w=200&h=200&q=75 location ~ (.+)\.(jpg|gif|png)@(\d+)w_(\d+)h_(\d+)Q_([rc])$ { # 方便除錯 error_log /usr/local/var/logs/nginx/xxx.com.imagefilter.error.log debug; # 限制referer,防盜鏈 # valid_referers xxx.com;#domain modify # if ($invalid_referer) {return 404;} set $w $3; #寬 set $h $4; #高 set $q $5; #圖片質量 set $type $6; set $image_path $1.$2; #真實圖片地址 set $cache_path $1_$3w_$4h_$5Q_$6.$2; #臨時檔案地址 if ($type = 'r') { set $type 'image-resize'; } if ($type = 'c') { set $type 'image-crop'; } set $image_uri /$type$image_path?w=$w&h=$h&q=$q; if (-f $document_root$cache_path) { rewrite (.+)\.(jpg|gif|png)@(\d+)w_(\d+)h_(\d+)Q_([rc])$ $1_$3w_$4h_$5Q_$6.$2; break; } if (!-f $document_root$cache_path) { # proxy_pass http://$server_name.$image_uri; # 必須填寫ip,填寫域名的話,nginx在啟動的時候會檢測域名,解析DNS,啟動後,在修改域名的解析是不生效的 # 實際上,本機填寫域名報500不生效,估計是DNS設定不對,會在server下新增 # resolver 127.0.0.1 valid=300s; proxy_pass http://127.0.0.1$image_uri; break; } proxy_store $document_root$cache_path; proxy_store_access user:rw group:rw all:r; proxy_temp_path /tmp/images; proxy_set_header Host $host; expires 10d; # 設定圖片過期時間10天 } location ~ /image-resize(.+)\.(jpg|gif|png) { rewrite /image-resize(.+)\.(jpg|gif|png)$ $1.$2 break; image_filter resize $arg_w $arg_h; image_filter_jpeg_quality $arg_q; image_filter_buffer 5M; try_files $1.$2 /img/notfound.jpg; } location ~ /image-crop(.+)\.(jpg|gif|png) { rewrite /image-crop(.+)\.(jpg|gif|png)$ $1.$2 break; image_filter crop $arg_w $arg_h; image_filter_jpeg_quality $arg_q; image_filter_buffer 5M; try_files $1.$2 /img/notfound.jpg; } https://blog.wangjunfeng.com/archives/669

相關推薦

nginx image_filter 配置記錄

nginx_image_filter http_image_filter_module 配置 ---------------------------------- 第一種: //官方配置 location /img/ { proxy_pass http://back

nginx的文件cache服務配置記錄(proxy_cache)

pan orm java conn efault out clu key oct 根據業務部門需求,申請一臺文件的cache服務器。如下記錄在單臺機器上部署Nginx緩存服務過程: nginx緩存配置(緩存配置的參數這裏就不做過多解釋了,在前面的文檔中已說明過,這裏只做

nginx配置記錄

cloud oca red pass server 轉發 proxy val 正常 http請求轉到https location / { access_log /usr/local/nginx/logs/access2.log access4;

nginx 動態縮略圖配置記錄

res AC inotify write home lis $1 nbsp 同時 最近公司商城的圖片嚴重影響到了網站的正常訪問,為了盡快解決這個問題,采用 圖片動態生成的處理方式。這裏用到了nginx的 http_image_filter_module 模塊,安裝nginx

nginx-配置記錄

dir pro ont index.jsp cores 包含 keepal redirect class  貼一個用過的nginx的配置,不包含https的配置 upstream front{ server 127.0.0.1:8080 we

windows下的nginx安裝和配置及與tomcat關聯配置記錄

   1. 官方中文說明:http://wiki.nginx.org/NginxChs  或者http://nginx.org/ 下載:當前穩定版: Nginx 1.0.5 | Nginx/windows 1.0.5 (更新記錄) (2011年7月19日) 我們下

Nginx的https配置記錄以及http強制跳轉到https的方法梳理

一、Nginx安裝(略)安裝的時候需要注意加上 --with-http_ssl_module,因為http_ssl_module不屬於Nginx的基本模組。Nginx安裝方法: 1 2 # ./configure --user=www --grou

Nginx縮圖和Fastdfs整合以及image_filter配置,7點經驗結論和5個參考資料

以下是7點經驗結論和5個參考資料1.Nginx單獨配置縮圖與Nginx和Fastdfs模組整合,配置是不一樣的。  非整合模式的配置,類似這樣的:  location ~* /(\d+)\.(jpg)$ {set $h $arg_h;   # 獲取引數h的值set $w $a

nginx+tomcat繫結域名配置記錄

記錄一下用nginx做反向代理,tomcat為web容器的域名繫結過程。 首先,當然是需要在域名管理器中配置域名指向自己的伺服器IP(當然,域名都沒有的還說個毛!) 然後就是配置nginx了, nginx基本配置: 找到nginx/conf/ngin

nginx配置 thinkphp5出現的問題記錄

因為最近開始整一些新的框架學習 以前接觸過tp3 但是時間太久了 然後就想著在學學tp5自己的系統是mac 的 所以自帶了一個apache composer安裝完tp5之後很省心 也不用什麼配置就成功了 然後傳專案到git上 在另外一臺ubuntu伺服器上把程式碼 git p

nginx 配置路由規則轉發配置記錄

ast 針對 roo page break 搜索 是否 localhost infa 工作中公司要求針對經銷商PC端和工廠PC端的訪問地址固定訪問。 經銷商PC端 http://localhost/ 工廠PC端 http://localhost/fac 文件

saltstack之多節點nginx安裝配置

saltstack 多節點 highstate nginx 多節點nginx安裝配置定義多節點cd /srv/salt vim top.slsbase: ‘server4.lalala.com‘: - nginx.install ‘server1.lalala.com‘: -

【Linux】nginx服務配置

網站目錄 write timeout per dex 修改 header www val 一. 部署LNMP環境 準備工作 Linux系統準備 設置IP 關閉防火墻

Nginx配置參數詳解,Nginx配置網站

lis javascrip ref 錯誤日誌 127.0.0.1 服務器配置 設置 代理服務器 減少 1.Niginx主配置文件參數詳解   a.Linux中安裝nginx。博文地址為:http://www.cnblogs.com/cindy-cindy/p/68474

Nginx配置1

syn user per area packages 多個 except put epo Nginx:http協議:web服務器(類似於httpd)、http reverse proxy(類似於httpd)、imap/pop3 reverse proxy NGINX is

Nginx配置3

ces allow nbsp nac host 源地址 上下 ror 不可用 ngx_http_upstream_module模塊 #分流The ngx_http_upstream_module module is used to define groups of

Nginx配置Nginx的負載均衡

如果 tail 運行 connect 其他 least label direct doc 閱讀目錄 參考的優秀文章 在本機運行2個Tomcat Nginx的負載均衡配置 參考的優秀文章 tomcat配置文件server.xml詳解 AJP協議總結與分析 Usi

linux上nginx配置虛擬主機的相關配置

nbsp 虛擬主機 服務 cnblogs linux extra 主機配置 conf com 1.配置主配置: nginx/conf/nginx.conf 2.虛擬主機配置:nginx/conf/extra/learn.weixin.com.conf 配置完後

nginx.conf配置文件

nginx.conf #user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid

nginx常用配置系列-虛擬主機

server com 文件 主機 -o 書寫 lena 準備 類型 本來準備詳盡的出一份nginx配置講解,但nginx功能配置繁多,平常使用中使用最多的一般有: 1. 虛擬主機配置 2. HTTPS配置 3. 靜態資源處理 4. 反向代理 ================