当前位置:网站首页>Openresty newly added module

Openresty newly added module

2022-06-09 06:18:00 Desert Effect

Preface



the other day , The front end presents a requirement , on-line web Server on gzip modular . It can save the exit bandwidth of the website , Speed up data transmission efficiency , Enhance user experience . Because of the Openresty and nginx There's a difference , Let's record the process .



Openresty Same as nginx equally , Adding modules requires recompiling



Openresty Add modules



<1> Install dependency packages

yum install -y gcc gcc-c++ zlib-devel pcre-devel openssl-devel readline-devel

If you are deploying a new one in another environment openresty, Dependency packages need to be installed . If it is already openresty Environmental Science , No need to install again



<1> Check out the online Openresty Compiler parameters for
( Because it is a new module , The original module cannot be lost , So first look at the original compilation parameters )

/usr/local/openresty/nginx/sbin/nginx -V
nginx version: openresty/1.15.8.1     
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.1rc1 --add-module=../echo-nginx-module-0.61 --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.31 --add-module=../ngx_lua-0.10.15 --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.7 --with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --add-dynamic-module=/data/openresty-1.15.8.1/../nginx-upsync-module-2.1.0 --add-module=/data/openresty-1.15.8.1/../naxsi/naxsi_src --add-dynamic-module=/data/openresty-1.15.8.1/../nginx-module-vts --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_ssl_module


<2> hold configure That line of compilation parameters is copied and arranged
( Convenient view )

cat 1.txt |awk '{for(i=1;i<=NF;++i) print $i}'  > configure_old.txt
--prefix=/usr/local/openresty/nginx
--with-cc-opt=-O2
--add-module=../ngx_devel_kit-0.3.1rc1
--add-module=../echo-nginx-module-0.61
--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.31
--add-module=../ngx_lua-0.10.15
--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.7
--with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib
--add-dynamic-module=/data/openresty-1.15.8.1/../nginx-upsync-module-2.1.0
--add-module=/data/openresty-1.15.8.1/../naxsi/naxsi_src
--add-dynamic-module=/data/openresty-1.15.8.1/../nginx-module-vts
--with-stream
--with-stream_ssl_module
--with-stream_ssl_preread_module
--with-http_ssl_module


OpenResty It's based on nginx Scalable Web platform , It's integrated lua And some other modules , Developers can use Lua Scripting language mobilization Nginx Various supported C as well as Lua modular , So it has some default compilation parameters , Compile time ./configure that will do , among Default module Parameters of There is no need to add... At compile time , Instead of the default parameter ( Add your own modules ) You have to add... At compile time

Exclude the following 3 strip , Everything else is openresty Default compilation parameters
We need to download the corresponding package when recompiling , And add... At compile time , Otherwise, the module is missing , Results in a newly compiled nginx After starting , There is a problem with the original service

--add-dynamic-module=/data/openresty-1.15.8.1/../nginx-upsync-module-2.1.0     #Nginx Modules for dynamic configuration , Through the pull  Consul  or  etcd ( And others ) Upstream data of , Implementation does not require reloading  Nginx , Dynamically modify back-end server properties 
--add-module=/data/openresty-1.15.8.1/../naxsi/naxsi_src                       #naxsi modular , Buildable WAF, prevent xss、 Anti injection attack 
--add-dynamic-module=/data/openresty-1.15.8.1/../nginx-module-vts              #Nginx Monitoring module , Can provide json、html、prometheus Format data output 


Be careful :
About the installation package of these modules , Don't delete it easily after compilation , Downloading is troublesome , Avoid compiling packages that are not installed later



<3> Check whether the module to be added is supported
( Get into openresty The source code package of )

./configure --help | grep http_gzip_static_module
./configure --help | grep with-http_flv_module
./configure --help | grep with-http_stub_status_module

To avoid compiling again later , Add modules that you may need



<4> recompile

./configure  --add-dynamic-module=/data/openresty-1.15.8.1/../nginx-upsync-module-2.1.0 --add-module=/data/openresty-1.15.8.1/../naxsi/naxsi_src --add-dynamic-module=/data/openresty-1.15.8.1/../nginx-module-vts  --with-http_gzip_static_module --with-http_flv_module --with-http_stub_status_module

 After successful compilation :
gmake

# Because the operation in this document is to add modules , There is already openresty Profile . must not install
#gmake install

Be careful :
If configured –prefix, The directory must be the same as the original nginx The directories in the compilation parameters of are the same



<5> Copy new nginx To directory

cd openresty-1.15.8.1/build/nginx-1.19.3/objs/nginx
cp nginx /usr/local/openresty/nginx/sbin/nginx_xin


<6> Test and compare nginx Compile parameters

cd /usr/local/openresty/nginx/sbin/
./nginx -t
./nginx_xin -t

./nginx -V
./nginx_xin -V

 see prefix Whether the directory of is consistent , new nginx Is there a lack of old nginx Parameters in 


<7>nginx restart

For example, the previous tests are successful , It can be restarted nginx
( If there are a large number of businesses, it is not recommended to restart directly , When the number of visitors is small )

nginx -s stop
mv nginx nginx_old
mv nginx_xin nginx
./nginx 

It can also be like nginx Smooth upgrade , restart nginx, Reference link :
https://blog.csdn.net/GX_1_11_real/article/details/85922283 Item 7




nginx gzip Configuration of



gzip on;                # On and off gzip Pattern 
gzip_min_length 1k;     #gizp Compress the starting point , File is larger than 1k To compress 
gzip_buffers 4 16k;     # Set the buffer size required for compression , With 4k In units of , If the document is 7k Then apply for 2*4k The buffer 
gzip_http_version 1.1;  # Set up gzip Compression is for HTTP Protocol version 
gzip_comp_level 2;      # Set up gzip The compression ratio of , 1-9  The bigger the number, the better the compression , More and more occupied CPU Time (1 The compression ratio is the smallest but the fastest  9 contrary )
gzip_types text/plain application/x-javascript text/css application/xml application/json application/javascript text/xml text/javascript image/jpeg image/gif image/png;     # The type of file to be compressed 
gzip_proxied any;       # Regardless of the back-end server headers What information does the head return , Compression is enabled unconditionally 
gzip_vary on;           # Whether in http header Add Vary: Accept-Encoding, Recommended Opening 
gzip_disable "MSIE [1-6].";     # Ban IE6 Of gzip Compress , Specify which ones are not required gzip Compressed browser ( Will and User-Agents Match ), Depend on PCRE library 


Verify that the configuration is normal and then reload

/usr/local/openresty/nginx/sbin/nginx -t
/usr/local/openresty/nginx/sbin/nginx -s reload
原网站

版权声明
本文为[Desert Effect]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/03/202203021425138632.html