0
点赞
收藏
分享

微信扫一扫

linux系统安装nginx中的subs-filter模块

闲云困兽 2022-06-23 阅读 32

debain系

nginx源里面一般都包含 nginx的第三方模块
所以对应已经安装了nginx 的系统可以直接安装第三方模块

sudo apt install libnginx-mod-http-subs-filter

centos 系

对于已经安装nginx的centos系统,只能重新编译包含subs-filter的模块nginx,然后替换过去

1. 查看nginx版本号,记录编译参数

nginx -V

输出:

nginx version: nginx/1.14.0 (Ubuntu)
built with OpenSSL 1.1.1 11 Sep 2018
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-GkiujU/nginx-1.14.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module

这里记录一下nginx 的版本,和configure参数,虽然比较长

2.下载 nginx 源码和 subs-filter模块

然后下载对应版本的nginx,并解压

wget http://nginx.org/download/nginx-1.14.0.tar.gz
tar -xvzf nginx-1.14.0.tar.gz

这里替换成你自己nginx版本号就可以下载下来了

下载subs-filter模块

git clone git://github.com/yaoweibin/ngx_http_substitutions_filter_module.git

3.开始编译

首先进入解压后的nginx的目录下面,执行

./configure 你原始的configure参数 --add-module=/git/ngx_http_substitutions_filter_module

这里注意 ​​--add-module​​​ 指定到你clone下的 subs-filter模块的目录下就可以了
这步骤运行会遇到很多种错误,下面是常见错误及解决办法

./configure: error: the HTTP rewrite module requires the PCRE library.
yum -y install pcre-devel
./configure: error: SSL modules require the OpenSSL library.
yum -y install openssl openssl-devel
./configure: error: the HTTP XSLT module requires the libxml2/libxslt
yum -y install libxml2 libxml2-dev libxslt-devel
./configure: error: the HTTP image filter module requires the GD library.
yum -y install gd-devel
./configure: error: perl module ExtUtils::Embed is required
yum -y install perl-devel perl-ExtUtils-Embed
./configure: error: the Google perftools module requires the Google perftools
library. You can either do not enable the module or install the library
yum install gperftools -y

如果上面没有找到你的报错,你可以自己推理一下依赖的名字,比如
报错内容是 ​​​requires the XX library.​​ 那么就安装一下

yum install xx-devel

如果上面步骤都弄好了,就可以编译了

make

这里注意不用​​make install​

4.检查编译好的 nginx

测试一下编译后的nginx是否已经包含了subs-filter模块

./objs/nginx -t

当然这里配置文件要用到 subs-filter模块(nginx -t可以后面指定配置文件路径,也可以不指定,不指定使用默认配置路径,由于你configure参数用的是一个所以这里编译好的指定的配置文件路径和原来也是一致的)
如果没有报错就说明 nginx 已经包含了 subs-filter模块了

5.开始替换

首先停止原nginx服务

service nginx stop

下面进行替换(当然在此之前你也可以先备份一下,毕竟玩linux可能会遇到各种问题)

cp ./objs/nginx /usr/sbin/nginx

然后正常进行启动nginx 就可以了

service nginx start

其他

不得不说,编译安装是真的费劲,还是debain好,安装模块很方便
不过通过这次编译安装也让我对编译安装的每一步有了一定了解
比如 ​​​make install​​​ 这一步其实就是将编译好的文件放到对应路径里面
而编译​​​make​​​ 这一步就已经做完了,这一步会生成可执行文件,用到的参数都是 ​​./config​​ 后面的


本文来自博客园,作者:​​Hello_wshuo​​​,​


举报

相关推荐

0 条评论