yum安裝的nginx新增模塊http_image_filter_module筆記


yum安裝的nginx新增模塊大概的思路

  1. 官方nginx.org 下載相同版本的nginx源碼包

  2. 編譯安裝並指定需要的模塊(第三方模塊需要單獨下載對應的包)

  3. 注意只編譯make,不安裝make install. 編譯完成會在objs目錄下生成可執行文件nginx

  4. 復制nginx 可執行文件 到cp objs/nginx /usr/sbin/


一、下載源碼包

當前yum安裝的nginx版本: nginx -v 1.16.0

當前nginx可執行文件:which nginx /usr/sbin/nginx ,最好先備份此文件

nginx.org 沒有找到1.16.0 , 這里下載1.16.1源碼包來代替

下載並解壓到: /usr/local/nginx-1.16.1目錄

開始編譯前先備份:

備份源nginx cp /usr/sbin/nginx /usr/sbin/nginx.bak

備份配置文件 nginx cp -r /etc/nginx /etc/nginx.bak

二、配置編譯的參數

查看nginx已經安裝的模塊 nginx -V

./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module  --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -fPIC' --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'

在上面的命令里面加上 --with-http_image_filter_module=dynamic 開始執行編譯,編譯的時候依賴的模塊沒有安裝導致錯誤,只需安裝對應的模塊即可。

我編譯的時候有依賴的兩個模塊沒有安裝:

./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

安裝pcre-devel: yum install pcre-devel

./configure: error: the HTTP image filter module requires the GD library.
You can either do not enable the module or install the libraries.

安裝 gd-devel : yum install gd-devel

總之缺什么就安裝什么,網上很多文章已經介紹了依賴的所有的模塊。

三、編譯源碼包

執行 make,切記不需要執行make install,此處只需要得到nginx重新編譯的可執行文件,並不需要重新安裝替換掉原來的nginx

執行完成會在 objs 目錄下生成對應的可執行文件nginx

復制圖片過濾模塊: cp objs/ngx_http_image_filter_module.so /usr/lib64/nginx/modules/

覆蓋nginx可執行文件: cp -rfp objs/nginx /usr/sbin/

四、nginx配置文件

/etc/nginx/nginx.conf 動態加載模塊 : load_module "modules/ngx_http_image_filter_module.so";

/etc/nginx/conf.d/test.conf 配置圖片處理

location ~* /(.+)\.(jpg|jpeg|gif|png)!(\d+)x(\d+)$ {
              set $w $3;
              set $h $4;
              image_filter resize  $w $h;
              image_filter_buffer  10M;
              image_filter_jpeg_quality 75;
              try_files /$1.$2  /notfound.jpg;
             #  expires 30d;
          }

nginx -t 檢查nginx配置語法是否OK、再重新啟動nginx即可

五、測試圖片縮放

原圖訪問:

縮略圖訪問:

參考下面兩篇就夠了啊

https://blog.csdn.net/zzy5066/article/details/81136273

https://www.cnblogs.com/lixigang/articles/5130052.html

https://www.cnblogs.com/tinywan/p/6965467.html nginx加載動態模塊


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM