nginx 流量拷贝模块 ngx_http_mirror_module 安装试用
1. 下载源码编译
https://nginx.org/download/nginx-1.13.4.tar.gz
2. 下载依赖模块包
这里直接yum 安装
yum -y install openssl openssl-devel
yum -y install pcre-devel
3. 安装
可以直接默认 ./configure
我是为了添加https 以及状态监测模块,还有四层负载均衡,比较好的地方是这个模块是
直接内置里面的。
./configure --prefix=/usr/local/nginx –with-http_ssl_module –with-http_stub_status_module -with-stream
make && make install
4. 使用
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
mirror /mirror; # 可配置多个
mirror_request_body off;
root html;
mirror /mirror2;
index index.html index.htm;
}
# mirror配置
location /mirror {
proxy_pass http://127.0.0.1:8080$request_uri;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
location /mirror2 {
proxy_pass http://127.0.0.1:8081$request_uri;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 8080;
server_name localhost;
location / {
root html2;
index index.html index.htm;
}
}
server {
listen 8081;
server_name localhost;
location / {
root html3;
index index.html index.htm;
}
}
5. 启动测试即可
/sbin/nginx -t
/sbin/nginx
6. 价值
流量拷贝、以前的方案可能有tcpcopy openresty capture_multi 等等,
原生内置了,就是好用,希望openresty 也内置进去,配置capture_muilt 还是有
点不是很方便,如果结合起来,那就太强大了。
7. 待确认
性能,稳定性,以及生产环境使用的坑。
8. 参考资料
https://nginx.org/en/docs/http/ngx_http_mirror_module.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)