current position:Home>Openresty+nginx image server configuration, add http_image_filter_module module

Openresty+nginx image server configuration, add http_image_filter_module module

2022-08-06 17:27:20Yin Changqing

Background

Pure NGINX configuration image server please refer to: Nginx picture and video server configuration_Yin Changqing's blog-CSDN blog

Openresty itself does not have an integrated image module by default, you need to manually compile the openresty method to add the module.

openresty download address, if openresty has been installed on the machine before, it is best to go to the official website to download the corresponding openresty source code

Deployment

Download

Official website address: OpenResty - Download

Compile openresty

tar -zxvf openresty-1.19.9.1.tar.gzcd openresty-1.19.9.1

Install the tools required for compilation

yum -y install gcc pcre-devel make zlib-devel openssl-devel libxml2-devel libxslt-devel gd-devel GeoIP-devel libatomic_ops-devel luajit luajit-devel perl-develperl-ExtUtils-Embed

Compile source code

First check what the original openresty installed

/usr/local/openresty/nginx/sbin/nginx -V

This will appear

configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.20 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.10 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-stream--with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module

When we compile, we only need to bring the data of --with-xxxxx, and add the module http_image_filter_module

Example:

./configure --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module --with-http_image_filter_module

Appears when configuration is complete

Type the following commands to build and install:gmakegmake install

Then execute

gmake && gmake install

It will appear when the execution is complete

gmake[2]: leave directory "/home/openresty-1.19.9.1/build/nginx-1.19.9"gmake[1]: leave directory "/home/openresty-1.19.9.1/build/nginx-1.19.9"mkdir -p /usr/local/openresty/site/lualib /usr/local/openresty/site/pod /usr/local/openresty/site/manifestln -sf /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/bin/openresty

At this time, when you execute nginx -V, you will find that the image module has been added successfully. If there is an error in the process, there are probably few tools. It can be solved by installing the few tools with yum.

The next step is to configure nginx.conf and restart openresty

 location ~ /img/(.*)_(\d+)x(\d+)(.*)$ {root /;rewrite ^/img/(\S)(\S)(.*)_(\d+)x(\d+)(.*)$ /home/imgs/$1$2/$3$6 break;image_filter resize $4 $5;image_filter_buffer 50M;image_filter_jpeg_quality 75;}# The regular processing link /img/F166666666_240.jpg will point to the local path /home/img/F1/66666666.jpg file# The picture will be scaled according to the width of 240, and the compression rate will be 75location ~ /img/(.*)_(\d+)(\.(.*))$ {root /;rewrite ^/img/(\S)(\S)(.*)_(\d+)(\.(.*))$ /home/imgs/$1$2/$3$5 break;image_filter resize $4 -;image_filter_buffer 50M;image_filter_jpeg_quality 75;}# The regular processing link /img/F166666666.jpg will point to the local path /home/img/F1/66666666.jpg filelocation ~ /img/(.*)$ {root /;rewrite ^/img/(\S)(\S)(.*)$ /home/imgs/$1$2/$3 break;}

Save reboot.

copyright notice
author[Yin Changqing],Please bring the original link to reprint, thank you.
https://en.qdmana.com/2022/218/202208061703170641.html

Random recommended