nginx线上流量复制

简介: nginx线上流量复制

一、背景

  • 在工作当中经常会遇到,测试环境好用,本地不好用的情况,这种情况要么就是版本的问题,要么就是数据的问题
  • 但是怎么能debug调试我们测试环境程序呢~

二、解决方案

⚠️:nginx实现的测试环境请求复制到本地,并进行debug调试

直接上代码

# 配置服务代理
          location /thread-test/ {
              # 主机地址
              #模拟nginx转发是测试后台的服务
              proxy_pass http://localhost:9902/thread-test/;
                # 流量复制
                mirror /mirror;
                mirror_request_body on;
          }
# 镜像站点
        location /mirror{
                internal;
                # 模拟本地的服务
                proxy_pass http://localhost:9905$request_uri;
                proxy_pass_request_body on;
                proxy_set_header X-Original-URI $request_uri;
        }
  • 好处
  • 既能解决debug调试的线上的测试环境,又不会阻塞线上环境的程序运行。

  • 这里只是放了一个用于测试的最原始的nginx.conf配置文件,
#user  nobody;
worker_processes  1;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
events {
    worker_connections  1024;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
    #access_log  logs/access.log  main;
    sendfile        on;
    #tcp_nopush     on;
    #keepalive_timeout  0;
    keepalive_timeout  65;
    #gzip  on;
    server {
        listen       80;
        server_name  localhost;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
            root   html;
            index  index.html index.htm;
        }
# 配置服务代理
          location /thread-test/ {
              # 主机地址
              proxy_pass http://localhost:9902/thread-test/;
                # 流量复制
                mirror /mirror;
                mirror_request_body on;
          }
# 镜像站点
        location /mirror{
                internal;
                proxy_pass http://localhost:9905$request_uri;
                proxy_pass_request_body on;
                proxy_set_header X-Original-URI $request_uri;
        }
        #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   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;
        #}
    }
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
    include servers/*;
}


相关文章
|
3月前
|
应用服务中间件 nginx
百度搜索:蓝易云【利用nginx内置ngx_http_mirror_module模块实现流量复制及流量放大】
以上就是使用Nginx内置 `ngx_http_mirror_module`模块实现流量复制和流量放大的简要示例。通过合理配置和利用该模块,可以实现更复杂的流量控制和调试需求。
58 1
|
19天前
|
存储 安全 应用服务中间件
解密Nginx限流机制:有效应对DDoS攻击与高并发流量
解密Nginx限流机制:有效应对DDoS攻击与高并发流量
31 0
|
2月前
|
负载均衡 监控 应用服务中间件
Nginx负载均衡:你的网站流量翻倍利器
Nginx负载均衡:你的网站流量翻倍利器
46 0
|
5月前
|
运维 监控 应用服务中间件
用 Golang 采集 Nginx 接口流量大小
用 Golang 采集 Nginx 接口流量大小
|
5月前
|
运维 应用服务中间件 nginx
运维(27)-部署流量代理(Nginx+haproxy)
运维(27)-部署流量代理(Nginx+haproxy)
64 0
|
缓存 算法 前端开发
网站流量日志埋点收集—后端脚本(nginx+lua)|学习笔记
快速学习网站流量日志埋点收集—后端脚本(nginx+lua)
494 0
网站流量日志埋点收集—后端脚本(nginx+lua)|学习笔记
|
运维 监控 安全
nginx、apache流量日志分析
nginx、apache流量日志分析
528 1
nginx、apache流量日志分析
|
Java 应用服务中间件 测试技术
Nginx 一个牛X的功能,流量拷贝!
将生产环境的流量拷贝到预上线环境或测试环境,这样做有很多好处
463 0
Nginx 一个牛X的功能,流量拷贝!
|
前端开发 Java 应用服务中间件
Nginx 又一牛 X 功能:流量拷贝
Nginx 又一牛 X 功能:流量拷贝
227 0
Nginx 又一牛 X 功能:流量拷贝