nginx增加第三方模塊


增加第三方模塊


============================================================

一、概述
nginx文件非常小但是性能非常的高效,這方面完勝apache。
nginx文件小的一個原因之一是nginx自帶的功能相對較少,好在nginx允許第三方模塊,第三方模塊使得
nginx越發的強大。

nginx已支持動態加載模塊

二、安裝第三方模塊
./configure --prefix=源安裝目錄 --add-module=/第三方模塊解壓目錄

以安裝ngx_cache_purge模塊實例
場景一: 在未安裝nginx的情況下安裝nginx第三方模塊
# ./configure \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--add-module=/nginx_module/ngx_cache_purge \
--add-module=/nginx_module/echo-nginx-module-0.58
# make
# make install
# /usr/local/nginx/sbin/nginx


場景二:在已安裝nginx情況下安裝nginx模塊
# /usr/local/nginx/sbin/nginx -V
# ./configure --prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--add-module=/nginx_module/ngx_cache_purge
# make
# cp objs/nginx /usr/local/nginx/sbin/nginx
# /usr/local/nginx/sbin/nginx -s reload

注意:

安裝nginx安裝第三方模塊實際上是使用–add-module重新編譯nginx二進制文件,不要make
install 而是直接把編譯目錄下objs/nginx 文件直接覆蓋老的 nginx文件


============================================================

例如:工作中我們還有這樣的需求,配置的nginx文件需要測試結果時,如果能夠打印出相應結果的話,就更有利於我們排錯了。其實在nginx有個第三方的模可以實現此功能,現在我們來做下配置

(1)查看我們nginx 安裝的模塊

[root@localhost ~]# /opt/data/nginx/sbin/nginx -V
nginx version: nginx/1.17.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/opt/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream

(2)下載模塊

[root@localhost ~]# wget https://github.com/openresty/echo-nginx-module/archive/v0.60.tar.gz
--2019-07-26 22:15:47--  https://github.com/openresty/echo-nginx-module/archive/v0.60.tar.gz
[root@localhost ~]# tar xf v0.60.tar.gz

(3)安裝模塊

到nginx安裝的解壓文件中

[root@localhost nginx-1.17.0]# ./configure --prefix=/opt/data/nginx 
--with-http_stub_status_module
--with-http_ssl_module
--with-stream
--add-module=/root/echo-nginx-module-0.60
[root@localhost nginx-1.17.0]# make
注意:不能 make install

(4)將生成的nginx新文件將舊文件覆蓋

[root@localhost nginx-1.17.0]# systemctl stop nginx
[root@localhost nginx-1.17.0]# cp objs/nginx /opt/data/nginx/sbin/nginx 
[root@localhost nginx-1.17.0]# systemctl start nginx
[root@localhost nginx-1.17.0]# nginx -V
nginx version: nginx/1.17.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/opt/data/nginx --with-http_stub_status_module --with-http_ssl_module --with-stream --add-module=/root/echo-nginx-module-0.61

 


免責聲明!

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



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