yum安装下的nginx,重新编辑安装添加模块和添加第三方模块

背景:centos7下yum直接安装的nginx,添加新模块
1、查看nginx版本模块
nginx -V
在这里插入图片描述
2、下载一个同版本的可编译的nginx

cd /tmp
wget http://nginx.org/download/nginx-1.12.2.tar.gz 
tar zxvf nginx-1.12.2.tar.gz && cd nginx-1.12.2

3、备份、备份文件

mv /usr/sbin/nginx /usr/sbin/nginx.2019 
cp -r /etc/nginx /etc/nginx.2019

4、安装依赖

yum -y install libxml2 libxml2-dev libxslt-devel gd-devel perl-devel perl-ExtUtils-Embed GeoIP GeoIP-devel GeoIP-data
yum -y install  --skip-broken gcc gcc-c++ autoconf automake
yum -y install --skip-broken zlib zlib-devel openssl-devel pcre-devel
yum groupinstall 'Development Tools' -y

5、检查模块是否支持,比如这次添加 limit 限流模块 和 stream 模块:

./configure --help | grep limit 

在这里插入图片描述
6、再加入安装第三方模块。比如ngx_log_if模块

(1)先到Github下载ngx_log_if地址https://github.com/cfsego/ngx_log_if/
(2)解压到/root/download/ngx_log_if-maste

(3)在编译文件后面加入 --add-module=/root/download/ngx_log_if-master (ngx_log_if模块的路径)

编译

./configure --user=www --group=www --prefix=/usr/share/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/lib/nginx/tmp/client_body --http-proxy-temp-path=/var/lib/nginx/tmp/proxy --http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi --http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi --http-scgi-temp-path=/var/lib/nginx/tmp/scgi --pid-path=/run/nginx.pid --lock-path=/run/lock/subsys/nginx --user=nginx --group=nginx --with-file-aio --with-http_auth_request_module --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module=dynamic --with-http_image_filter_module=dynamic --with-http_geoip_module=dynamic --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module=dynamic --with-mail=dynamic --with-mail_ssl_module --with-pcre --with-pcre-jit --with-stream=dynamic --with-stream_ssl_module --with-debug --with-cc-opt=’-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -m64 -mtune=generic’ --with-stream --add-module=/root/download/ngx_log_if-master

注意后面是新加的第五步和第六步模块
7、编译通过,继续验证
继续输入:

make -j2 

禁止:千万不要继续输入“make install”,以免现在的nginx出现问题
以上完成后,会在objs目录下生成一个nginx文件,先验证:

objs/nginx -t 
objs/nginx -V

8、文件替换,并重启
以上成功后:

cp objs/nginx /usr/sbin/ 
nginx -s reload

ngx_log_if用法:
配置access_log_bypass_if到nginx.conf配置文件中
server {
location / {
access_log_bypass_if (KaTeX parse error: Expected 'EOF', got '#' at position 16: status = 404); #̲不记录404状态的所有日志信息…uri ~* ‘images’); #不记录uri中所有images目录下文件的日志信息
access_log_bypass_if (KaTeX parse error: Expected 'EOF', got '#' at position 23: …/index.html'); #̲不记录uri为/index.h…host ~* ‘tonv.cc’); #不记录host为tonv.cc的所有日志信息
}
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值