nginx平滑升级(添加echo功能)配置和状态监控

本文介绍了如何在nginx上平滑升级并添加echo模块,详细阐述了配置过程,包括删除旧版、从github获取模块源码、重新编译安装。接着讲解了location的使用策略,如路径匹配优先级,并涉及访问控制、用户认证和https配置。最后,提到了通过zabbix监控nginx状态页面的方法,包括编写监控脚本、添加监控主机、创建监控项和监控图像。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

(添加echo模块)配置

1.先去github或者gitee中找到nginx_module_echo-master.zip包
2.将原来的ngin-1.20.1删除,重新编译安装

[root@host src]# ls
debug  kernels  nginx-1.20.1.tar.gz  wujunze-nginx_module_echo-master.zip
[root@host src]# yum -y install unzip
[root@host src]# unzip wujunze-nginx_module_echo-master.zip 
Archive:  wujunze-nginx_module_echo-master.zip
cc5135fd7a7c87ccac48fd05509396443c71c065
   creating: nginx_module_echo/
 extracting: nginx_module_echo/.gitignore  
  inflating: nginx_module_echo/LICENSE  
  inflating: nginx_module_echo/README.md  
  inflating: nginx_module_echo/README_zh.md  
  inflating: nginx_module_echo/config  
   creating: nginx_module_echo/src/
  inflating: nginx_module_echo/src/ngx_http_echo_module.c  
[root@host src]# tar xf nginx-1.20.1.tar.gz   
[root@host src]# ls
debug  kernels  nginx-1.20.1  nginx-1.20.1.tar.gz  nginx_module_echo  wujunze-nginx_module_echo-master.zip
  • 查看之前的安装配置
[root@host ~]# nginx -V
nginx version: nginx/1.20.1
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-2) (GCC) 
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log
  • 开始编译安装
[root@host nginx-1.20.1]#  ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --add-module=../nginx_module_echo

可以发现现在多了一个objs目录
[root@host nginx-1.20.1]# ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  Makefile  man  objs  README  src
[root@host nginx-1.20.1]# make

[root@host nginx-1.20.1]# ls objs/
addon  autoconf.err  Makefile  ngx_auto_config.h  ngx_auto_headers.h  ngx_modules.c  src
[root@host nginx-1.20.1]# ls objs/
addon         Makefile  nginx.8            ngx_auto_headers.h  ngx_modules.o
autoconf.err  nginx     ngx_auto_config.h  ngx_modules.c       src

替换nginx文件
[root@host nginx-1.20.1]# pkill nginx;\cp objs/nginx /usr/local/nginx/sbin/;nginx 
[root@host nginx-1.20.1]# nginx -V
nginx version: nginx/1.20.1
built by gcc 8.5.0 20210514 (Red Hat 8.5.0-2) (GCC) 
built with OpenSSL 1.1.1k  FIPS 25 Mar 2021
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-debug --with-http_ssl_module --with-http_realip_module --with-http_image_filter_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --add-module=../nginx_module_echo

location应用

修饰符 功能
= 精确匹配
~ 正则表达式模式匹配,区分大小写
~* 正则表达式模式匹配,不区分大小写
^~ 前缀匹配,类似于无修饰符的行为,也是以指定模块开始,不同的是,如果模式匹配,那么就停止搜索其他模式了,不支持正则表达式
@ 定义命名location区段,这些区段客户端不能访问,只可以由内部产生的请求来访问,如try_files或error_page等
  • ( location = 路径 ) --> ( location ^~ 路径 ) --> ( location ~ 正则 ) --> ( location ~* 正则 ) --> ( location 路径 )
[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
......
        location /abc {
   
   
            echo "hehe";
        }
        #error_page  404              /404.html;
......
用windows的cmd查看

在这里插入图片描述
在这里插入图片描述

精确查找
[root@host ~]# vim /usr/local/nginx/conf/nginx.conf
......
        location = /abc {
   
   
            echo "hehe";
        }
......

在这里插入图片描述


                
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值