1.ngx_http_mirror_module
nginx從1.13.4開始新增(ngx_http_mirror_module)模塊,顧名思義,可以將一個請求以鏡像請求的方式發送到另外的服務器,通常也叫請求複製,可以用於測試環境模擬真實環境的請求。
2.使用nginx1.14進行測試
關於鏡像請求的配置
server {
listen 8081;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location /test/ {
mirror /mirror/; # 配置鏡像請求
proxy_pass http://localhost/;
}
location /mirror/ { # 鏡像請求
proxy_pass http://192.168.3.8/;
}
#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;
#}
}
我們通過訪問http://192.168.3.15:8081/test/時候,192.168.3.8上的80端口也會有請求
192.168.3.8上nginx日誌,請求是從3.15發送過來:
3.幾點說明
- 鏡像請求的返回結果不會被處理;
- 可以填寫多個鏡像請求,保持平級即可;
- internal參數配置後,mirror請求只能被內部識別,外部訪問會404錯誤;