n7.Nginx 第三方模块

news/2024/9/7 4:46:28 标签: nginx, 运维

Nginx 第三方模块

第三模块是对nginx 的功能扩展,第三方模块需要在编译安装Nginx 的时候使用参数–add-module=PATH指定路径添加,有的模块是由公司的开发人员针对业务需求定制开发的,有的模块是开 源爱好者开发好之后上传到github进行开源的模块,nginx的第三方模块需要从源码重新编译进行支持

nginxmodulevts__6">1. nginx-module-vts 模块实现流量监控

[root@Ubuntu2204 ~]#cd /usr/local/src/
[root@Ubuntu2204 ~]#git clone https://github.com/vozlt/nginx-module-vts.git
[root@Ubuntu2204 src]#ls
nginx-1.22.1  nginx-1.22.1.tar.gz  nginx-module-vts
[root@Ubuntu2204 src]#cd nginx-1.22.1/
[root@Ubuntu2204 nginx-1.22.1]#nginx -V
nginx version: nginx/1.22.1
built by gcc 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04) 
built with OpenSSL 3.0.2 15 Mar 2022
TLS SNI support enabled
configure arguments: --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module

[root@Ubuntu2204 nginx-1.22.1]#./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/usr/local/src/nginx-module-vts

[root@Ubuntu2204 nginx-1.22.1]#make && make install

[root@Ubuntu2204 nginx-1.22.1]#vim /apps/nginx/conf/conf.d/mirrors.conf

vhost_traffic_status_zone;

server {
    listen 80;
    server_name mirrors.anan.org;
    root /data/nginx/html/mirrors;
    charset utf-8;
    server_tokens off;
    access_log /data/nginx/logs/mirrors-access.log; 
    error_log /data/nginx/logs/mirrors-error.log;
    
    location /status {
    vhost_traffic_status_display;
    vhost_traffic_status_display_format html;
    }
} 

[root@Ubuntu2204 nginx-1.22.1]#systemctl restart nginx.service 

#浏览器输入 mirrors.anan.org/status

在这里插入图片描述

2. echo 模块实现信息显示

开源的echo模块可以用来打印信息,变量等

[root@Ubuntu2204 ~]#cd /usr/local/src
[root@Ubuntu2204 src]#git clone https://github.com/openresty/echo-nginx-module.git
[root@Ubuntu2204 src]#ls
echo-nginx-module  nginx-1.22.1  nginx-1.22.1.tar.gz  nginx-module-vts
[root@Ubuntu2204 src]#cd nginx-1.22.1/
[root@Ubuntu2204 nginx-1.22.1]#./configure --prefix=/apps/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream --with-stream_ssl_module --with-stream_realip_module --add-module=/usr/local/src/nginx-module-vts --add-module=/usr/local/src/echo-nginx-module
[root@Ubuntu2204 nginx-1.22.1]#make && make install
[root@Ubuntu2204 nginx-1.22.1]#systemctl restart nginx
[root@Ubuntu2204 nginx-1.22.1]#vim /apps/nginx/conf/conf.d/mirrors.conf
vhost_traffic_status_zone;

server {
    listen 80;
    server_name mirrors.anan.org;
    root /data/nginx/html/mirrors;
    charset utf-8;
    server_tokens off;
    access_log /data/nginx/logs/mirrors-access.log; 
    error_log /data/nginx/logs/mirrors-error.log;

    location /main {
     index index.html;
     default_type text/html;
     echo "hello world,main-->";
     echo $remote_addr ;
     echo_reset_timer;
     echo_location /sub1;
     echo_location /sub2;
     echo "took $echo_timer_elapsed sec for total.";
 }
 location /sub1 {
     echo_sleep 1;
     echo sub1;
 }
 location /sub2 {
     echo_sleep 1;
     echo sub2;
 }
    
} 

[root@Ubuntu2204 nginx-1.22.1]#nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
[root@Ubuntu2204 nginx-1.22.1]#nginx -s reload

# 测试查看结果(另一台客户端rocky查看)
[root@Rocky8 ~]#curl mirrors.anan.org/main
hello world,main-->
10.0.0.8
sub1
sub2
took 2.004 sec for total.

# 测试查看结果(浏览器查看)

在这里插入图片描述


http://www.niftyadmin.cn/n/5568319.html

相关文章

【刷题汇总 -- 压缩字符串(一)、chika和蜜柑、 01背包】

C日常刷题积累 今日刷题汇总 - day0181、压缩字符串(一)1.1、题目1.2、思路1.3、程序实现 2、chika和蜜柑2.1、题目2.2、思路2.3、程序实现 3、 01背包3.1、题目3.2、思路3.3、程序实现 -- dp 4、题目链接 今日刷题汇总 - day018 1、压缩字符串(一) 1.1、题目 1.2、思路 读完…

【ELK】window下ELK的安装与部署

ELK的安装与部署 1. 下载2. 配置&启动2.1 elasticsarch2.1.1 生成证书2.1.2 生成秘钥2.1.3 将凭证迁移到指定目录2.1.4 改配置2.1.5 启动2.1.6 访问测试2.1.7 生成kibana账号 2.2 kibana2.2.1 改配置2.2.2 启动2.2.3 访问测试 2.3 logstash2.3.1 改配置2.3.2 启动 2.4 file…

R语言模型评估网格搜索

### 网格搜索 ### install.packages("gbm") set.seed(1234) library(caret) library(gbm) fitControl <- trainControl(method = repeatedcv,number = 10,repeats = 5) # 设置网格搜索的参数池 gbmGrid <- expand.grid(interaction.depth = c(3,5,9),n.trees =…

(Qt) 文件读写基础

文章目录 &#x1f5c2;️前言&#x1f4c4;ref&#x1f4c4;访问标记&#x1f5c3;️enum 标记 &#x1f5c2;️Code&#x1f4c4;demo&#x1f4c4;分点讲解&#x1f5c3;️继承体系&#x1f5c3;️打开/关闭&#x1f5c3;️写&#x1f5c3;️读 &#x1f5c2;️END&#x1f…

2024.7.22

2024.7.22 【“大暑三秋近&#xff0c;林钟九夏移。桂轮开子夜&#xff0c;萤火照空时。”】 Monday 六月十七 大暑 T1 难&#xff08;nan&#xff09; 【题目描述】 给定两个字符串a,b&#xff0c;从a中选一段前缀&#xff0c;b中选一段后缀&#xff08;前后缀都可以为 空&a…

CVE-2020-7248 OpenWRT libubox堆栈溢出漏洞复现(更新中)

提要 该文档会一直处于更新当中&#xff0c;当状态为完毕后&#xff0c;才是更新完成。由于网络上关于该漏洞原理的分析文档和资源实在是太少&#xff0c;而本人关于该方向也才是刚入门&#xff0c;能力有限&#xff0c;所以复现需要的时间较长&#xff0c;需要补充和学习的东西…

Html review1

1、块元素和行内元素 块元素独占一行 p、h 行内元素的宽度是内容撑起来的&#xff0c;几个行内可以在一行a、strong、em 2、视频音频播放 视频&#xff1a; video src" 资源 路径" controls进度条 autoplay自动播放 音频&#xff1a; audio src“资源路径” controls…

【ProtoBuf】通讯录实现(网络版)

Protobuf 还常用于通讯协议、服务端数据交换场景。那么在这个示例中&#xff0c;我们将实现一个网络版本的通讯录&#xff0c;模拟实现客户端与服务端的交互&#xff0c;通过 Protobuf 来实现各端之间的协议序列化。 需求如下&#xff1a; 客户端可以选择对通讯录进行以下操…