Nginx爲已安裝nginx動態添加模塊

這裏以安裝第三方ngx_http_google_filter_module模塊爲例nginx

nginx的模塊是須要從新編譯nginx,而不是像apache同樣配置文件引用.sogit

  1. 下載第三方擴展模塊ngx_http_google_filter_module

cd /data/software/

git clone https://github.com/cuber/ngx_http_google_filter_module

  1. 查看nginx編譯安裝時安裝了哪些模塊

將命令行切換到nginx執行程序所在的目錄並輸入./nginx -V,具體以下:github

[root@liuyazhuang121 sbin]# ./nginx -V apache

nginx version: nginx/1.9.3 ide

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC) ui

built with OpenSSL 1.0.2 22 Jan 2015 google

TLS SNI support enabled 命令行

configure arguments: --prefix=/usr/local/nginx-1.9.3 --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 ssl

[root@liuyazhuang121 sbin]#get

能夠看出編譯安裝使用了--prefix=/usr/local/nginx-1.9.3 --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這些參數。

  1. 加入須要安裝的模塊,從新編譯

這裏添加-–add-module=/data/software/ngx_http_google_filter_module

具體以下:

複製代碼代碼以下:

./configure --prefix=/usr/local/nginx-1.9.3 --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,否則就真的覆蓋

  1. 替換nginx二進制文件

備份原來的nginx執行程序

cp /usr/local/nginx-1.9.3/sbin/nginx /usr/local/nginx-1.9.3/sbin/nginx.bak

將新編譯的nginx執行程序複製到/usr/local/nginx/sbin/目錄下

cp /opt/nginx/nginx /usr/local/nginx/sbin/

相關文章
相關標籤/搜索