nginx实时流量拷贝ngx_http_mirror_module

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

ngx_http_mirror_module用于实时流量拷贝

请求一个接口,想实时拷贝这个请求转发到自己的服务上,可以使用ngx_http_mirror_module模块。
官网好像就两个指令,

mirror
mirror_request_body

在这里插入图片描述

例子

案例流程:

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

~/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上,这里可以看到的确有两个请求过来。
    在这里插入图片描述

相关推荐

  1. 从零手写实现 nginx-10-sendfile 零拷贝 zero-copy

    2024-03-17 10:08:02       6 阅读
  2. Nginx实现流量控制模块的配置与应用!

    2024-03-17 10:08:02       31 阅读
  3. 拷贝实现方法

    2024-03-17 10:08:02       36 阅读
  4. 拷贝实现方式

    2024-03-17 10:08:02       7 阅读
  5. c++对象拷贝与堆中的对象实例拷贝

    2024-03-17 10:08:02       35 阅读
  6. 拷贝与深拷贝全面解析及实战

    2024-03-17 10:08:02       6 阅读
  7. 拷贝和浅拷贝的区别,如何实现一个深拷贝

    2024-03-17 10:08:02       11 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-17 10:08:02       16 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-17 10:08:02       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-17 10:08:02       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-17 10:08:02       18 阅读

热门阅读

  1. ChatGPT:突破写作限制,开启论文写作新境界

    2024-03-17 10:08:02       18 阅读
  2. axios入门

    2024-03-17 10:08:02       17 阅读
  3. LeetCode题练习与总结:解数独

    2024-03-17 10:08:02       19 阅读
  4. Axios 中的文件上传(Upload File)方法

    2024-03-17 10:08:02       18 阅读
  5. linux系统kubernetes的yaml文件

    2024-03-17 10:08:02       21 阅读
  6. CMake官方教程9--打包文件

    2024-03-17 10:08:02       19 阅读
  7. JWT令牌

    JWT令牌

    2024-03-17 10:08:02      21 阅读
  8. React懒加载

    2024-03-17 10:08:02       21 阅读