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;
proxy_pass http://backend/api/v1/test;
}
location /mirror {
internal;
proxy_pass http://www.xxx.com/api/v1/test;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
}
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 / {
try_files $uri $uri/ /index.php?$query_string;
}
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;
}
}