1.1. nginx 请求流量复制

  • nginx 1.13.4及后续版本内置ngx_http_mirror_module模块
  • 使用proxy 代理到自身其他端口,同时实现流量转发
  • internal 是针对内部地址开发
  • mirror 流量转发目标地址 ,多个可以实现流量扩大

1.1.1. 针对单独目标的流量转发

pstream backend {
    server 127.0.0.1:8050;
}
server{
        listen 80;

        server_name xxx.xxx.xxx;
        root /path;
        index index.php index.html index.htm;
    ## 针对单独目标的流量转发
    location ^~ /api/v1/xxx {
        mirror /mirror;
       # mirror /mirror; ## 多个可扩大流量
       # mirror /mirror;
           ## 代理到自身 8050端口 同时 复制到mirror 
        proxy_pass http://backend/api/v1/test;
    }
    location /mirror {
        internal; ## 外部访问 404 
        ## 转发目标地址
        proxy_pass http://www.xxx.com/api/v1/test;
    }
       location / {

                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.php?$query_string;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }

        location ~ \.php$ {
                try_files $uri /index.php =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/tmp/php-cgi.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }


        location ^~ /.git
        {
                return 444;
        }



        error_log /home/wwwlogs/error_Xserver.log;
        access_log /home/wwwlogs/access_Xserver.log main;
}
server{
        listen 8050;
        server_name xxx.xxx.xxx;
        root /path;
        index index.php index.html index.htm;

       location / {

                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ /index.php?$query_string;
                # Uncomment to enable naxsi on this location
                # include /etc/nginx/naxsi.rules
        }
        location ~ \.php$ {
                try_files $uri /index.php =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/tmp/php-cgi.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

results matching ""

    No results matching ""