nginx实时流量拷贝ngx_http_mirror_module

参考:
Module ngx_http_mirror_module
Nginx流量拷贝ngx_http_mirror_module模块使用方法详解

ngx_http_mirror_module用于实时流量拷贝

请求一个接口,想实时拷贝这个请求转发到自己的服务上,可以使用ngx_http_mirror_module模块。

官网好像就两个指令,

bash 复制代码
mirror
mirror_request_body

例子

案例流程:

curl client -> 本地nginx -> 测试服务(这里用的是一个nginx模拟的服务)

bash 复制代码
~/data/nginx/web/conf/ cat default.conf 

upstream kevin-mirror2 {
    server 192.168.52.133:80;   # 这个实际上是另一个nginx
}
server {

    listen       80;
    listen  [::]:80;
    server_name  localhost;

    access_log  /var/log/nginx/host.access.log  main;

    location ~* \.(jpg|JPG|PNG|jpeg|png|gif)$ {
        root /static;
    }

    location / {
#        root   /usr/share/nginx/html;
#        index  index.html index.htm;
        mirror /mirror;
        proxy_pass http://kevin-mirror2;
    }

    location /mc {
        set            $memcached_key "$uri";
        memcached_pass 192.168.59.213:11211;
    }

    location = /mirror {
        internal;
        access_log /usr/share/nginx/html/mirror.log  main;
        proxy_pass http://kevin-mirror2$request_uri;   # 这里这里要写成http://kevin-mirror2$request_uri,写成http://kevin-mirror2转发到后端就变成了/mirror 
        proxy_pass_request_body off;
        proxy_set_header Content-Length "";
        proxy_set_header X-Original-URI $request_uri;
        proxy_set_header X-Real-IP $remote_addr;
    }


    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

(p38)  ~/data/nginx/web/conf/ 
  1. 请求镜像端点,返回404

    本地nginx显示404
  2. 访问/本地nginx返回页面
  • 本地nginx返回页面
  • 本地nginxnginx的日志
  • 代理的测试服务。因为是测试,我把请求都转到了测试nginx上,这里可以看到的确有两个请求过来。
相关推荐
刘某的Cloud3 分钟前
硬链接 和 软链接 区别
运维·系统·硬链接·软链接
jiayong236 分钟前
harness 与 hermes-agent 扩展性、安全与运维
运维·人工智能·安全·ai·架构·智能体·harness
STDD22 分钟前
Linux Namespace:容器隔离的底层原理,PID、网络、挂载隔离实战
linux·运维·网络
todoitbo22 分钟前
一台 2C2G 服务器上的 KingbaseES 安装记录
运维·服务器·数据库·国产数据库
Gong-Yu38 分钟前
MySQL数据库运维(1)
运维·数据库·mysql·慢查询
Yang961139 分钟前
宽频高精度!鼎讯信通 OM-T 台式频谱分析仪风电实验室专用
大数据·运维·网络
AugustRed1 小时前
Docker原理和使用指南、常用命令、Compose多容器部署
运维·docker·容器
着迷不白1 小时前
实战一:用户、权限、组 案例
linux·运维
乐兮创想 小林1 小时前
企业官网的运维分工模型:内容自助、Bug 终身免费修与服务器托管的边界设计
运维·服务器·bug·网站建设·企业官网·北京网站建设公司
乐兮创想 小林1 小时前
生物科技官网的工程化设计:产品×应用二维信息架构、多语言与国际化 SEO 实践
运维·服务器·bug·网站建设·企业官网·北京网站建设公司