寫在前面
很多時候,我們根據當時的項目情況和業務需求安裝完Nginx后,后續隨著業務的發展,往往會給安裝好的Nginx添加其他的功能模塊。在為Nginx添加功能模塊時,要求Nginx不停機。這就涉及到如何為已安裝的Nginx動態添加模塊的問題。本文,就和小伙伴們一起探討如何為已安裝的Nginx動態添加模塊的問題。
為Nginx動態添加模塊
這里以安裝第三方ngx_http_google_filter_module模塊為例。
Nginx的模塊是需要重新編譯Nginx,而不是像Apache一樣配置文件引用.so
下載第三方擴展模塊ngx_http_google_filter_module
# cd /data/software/
# git clone https://github.com/cuber/ngx_http_google_filter_module
查看nginx編譯安裝時安裝了哪些模塊
將命令行切換到Nginx執行程序所在的目錄并輸入./nginx -V,具體如下:
[root@binghe sbin]# ./nginx -V
nginx version: nginx/1.19.1
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)
built with OpenSSL 1.0.2 22 Jan 2015
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.19.1 --with-openssl=/usr/local/src/openssl-1.0.2 --with-pcre=/usr/local/src/pcre-8.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-http_ssl_module
[root@binghe sbin]#
可以看出編譯安裝Nginx使用的參數如下:
--prefix=/usr/local/nginx-1.19.1 --with-openssl=/usr/local/src/openssl-1.0.2 --with-pcre=/usr/local/src/pcre-8.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-http_ssl_module
加入需要安裝的模塊,重新編譯
這里添加 --add-module=/data/software/ngx_http_google_filter_module
具體如下:
./configure --prefix=/usr/local/nginx-1.19.1 --with-openssl=/usr/local/src/openssl-1.0.2 --with-pcre=/usr/local/src/pcre-8.37 --with-zlib=/usr/local/src/zlib-1.2.8 --with-http_ssl_module -–add-module=/data/software/ngx_http_google_filter_module
如上,將之前安裝Nginx的參數全部加上,最后添加 --add-module=/data/software/ngx_http_google_filter_module
之后,我們要進行編譯操作,如下:
# make //千萬不要make install,不然就真的覆蓋
這里,需要注意的是:不要執行make install命令。
替換nginx二進制文件
# 備份原來的nginx執行程序
# mv /usr/local/nginx-1.19.1/sbin/nginx /usr/local/nginx-1.19.1/sbin/nginx.bak
# 將新編譯的nginx執行程序復制到/usr/local/nginx-1.19.1/sbin/目錄下
# cp /opt/nginx/sbin/nginx /usr/local/nginx-1.19.1/sbin/
好了,今天就聊到這兒吧!別忘了點個贊,給個在看和轉發,讓更多的人看到,一起學習,一起進步!!
以上就是為Nginx動態添加模塊的方法的詳細內容,更多關于Nginx動態添加模塊的資料請關注腳本之家其它相關文章!