Nginx 负载均衡下的ip地址映射写入到日志
stream 流配置
stream {
upstream cloudsocket {
# hash $remote_addr consistent;
# $binary_remote_addr;
server 192.168.0.152:3306 backup;
server 192.168.0.151:3306 max_fails=1 fail_timeout=1s;
}
server {
listen 3306;#数据库服务器监听端口
proxy_connect_timeout 10s;
proxy_timeout 300s;#设置客户端和代理服务之间的超时时间,如果5分钟内>没操作将自动断开。
proxy_pass cloudsocket;
}
log_format proxy "$upstream_addr";
map $bytes_received $loggable {
0 0;
default 1;
}
access_log /nginx.txt proxy if=$loggable;
open_log_file_cache off;
}
nginx.txt就是nginx的日志,放在/文件夹下
http server location配置
location ~* \.(txt){
root /;
}