Bboysoul's Blog

首页 公告 RSS

已编译安装的nginx添加模块

September 1, 2017 本文有 307 个字 需要花费 1 分钟阅读

简介

今天搭建网站的时候发现原来编译好的nginx中没有我需要的模块,这个时候就需要往nginx中动态的添加模块了

操作

首先看一下自己现在的nginx版本

[root@vultr src]# nginx -V
nginx version: nginx/1.10.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) 
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module

上面有编译的参数,这个很重要
之后下载对应的nginx版本,解压
tar -zxvf nginx-1.10.0.tar.gz
下载模块
git clone https://github.com/cuber/ngx_http_google_filter_module
git clone https://github.com/yaoweibin/ngx_http_substitutions_filter_module
cd nginx-1.10.0
接着编译,编译的时候要加入要增加模块只要在编译的时候添加–add-module后面加上模块路径就好了
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-ipv6 --with-http_sub_module --add-module=../ngx_http_google_filter_module --add-module=../ngx_http_substitutions_filter_module
接着make记住不能make install
之后替换nginx二进制文件
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
cp objs/nginx /usr/local/nginx/sbin/
测试新的nginx是否正确

[root@vultr sbin]# ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

重启服务器
sudo service nginx reload

完成
Have Fun


Tags:

本站总访问量 本站总访客数