zoukankan      html  css  js  c++  java
  • Nginx流量复制

    生产环境出现的Bug在测试环境无法复现(即使是数据同步,代码同步也未排查出来),所以打算做个流量复制。

    流量复制模块:ngx_http_mirror_module

    user nginx;
    worker_processes auto;
    error_log /var/log/nginx/error.log;
    pid /run/nginx.pid;
    
    # Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
    include /usr/share/nginx/modules/*.conf;
    
    events {
        worker_connections 1024;
    }
    
    http {
        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  /var/log/nginx/access.log  main;
    
        sendfile            on;
        tcp_nopush          on;
        tcp_nodelay         on;
        keepalive_timeout   65;
        types_hash_max_size 2048;
    
        include             /etc/nginx/mime.types;
        default_type        application/octet-stream;
    
        # Load modular configuration files from the /etc/nginx/conf.d directory.
        # See http://nginx.org/en/docs/ngx_core_module.html#include
        # for more information.
        include /etc/nginx/conf.d/*.conf;
    
        server {
            listen 8282;
            server_name  _;
            access_log  /var/log/nginx/access.log;
            location / {
                index index.html;
                root /usr/share/nginx/html;
            }
        }
    
        server{
        	listen 8181;
       		server_name localhost;
        	access_log /var/log/nginx/mirror_access.log;
    	}
        
        upstream back {
            server 127.0.0.1:8282;
        }
        upstream mirror1 {
            server 127.0.0.1:8181;
        }
        server {
            listen       80;
            server_name  _;
    
            location / {
                mirror /mirror1;
                proxy_pass http://back;
    	}
    
            location = /mirror1 {
                proxy_pass http://mirror1$request_uri;
            }
    
            include /etc/nginx/default.d/*.conf;
    
        }
    
    }

    配置说明

    location / {                        # location /指定了源uri为/,也可以定义为其他指定接口
        mirror /mirror1;                # mirror /mirror指定镜像uri为/mirror,有多个需要复制流量的,可以配置多条
        mirror /mirror1;                # 配置多条情况下,将会起到流量放大的作用,即主配置请求一次,镜像端会有两次
      # mirror_request_body on;         # 指定是否镜像请求body部分,请求自动缓存;
        proxy_pass http://back;      # 指定处理主流量的后端Server
    }
    location = /mirror1 {
        internal;       # 指定此location只能被“内部的”请求调用,外部的调用请求会返回”Not found” (404)
        proxy_pass http://mirror1$request_uri;    # 指定将要复制流量的Server1
    }

    本文来自博客园,作者:MegaloBox,转载请注明原文链接:https://www.cnblogs.com/cpw6/p/15509088.html

  • 相关阅读:
    罗马数字转整数
    对称的二叉树
    python中列表,元组,字符串 互相转换
    python django 批量上传文件并绑定对应文件的描述
    python django mkdir和makedirs的用法
    python 获取两位的月份(09)和天数(09)
    django 注册后台管理 在debug=true能行,在debug=false不能显示出管理标签
    django OperationalError: unable to open database file 创建数据库
    网站安全保证设置及网站认证
    动态的有序分类导航:每个一级标题下都有多个二级标题。
  • 原文地址:https://www.cnblogs.com/cpw6/p/15509088.html
Copyright © 2011-2022 走看看