配置文件【四层代理】
nginx
graph LR
A[nginx.conf]
B[global]
C[http]
C1[upstream]
C2[server]
C21[location]
C211[if]
D[stream]
D1[upstream]
D2[server]
A -.->|worker进程配置| B
A -.->|http服务配置| C
C -.-> C1
C -.-> C2
C2 -.-> C21
C21 -.-> C211
D -.-> D1
D -.-> D2
A -.- |4层反向代理|D
subgraph 反向代理和http服务
C1
C2
end
subgraph 7层服务配置
C
end
subgraph 4层反向代理
D1
D2
end
subgraph 4层服务配置
D
end
subgraph 全局配置
B
end
subgraph 主配置文件
A
end
四层代理
nginx 在1.9 版本后开始支持 4层代理
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
stream {
log_format main '$remote_addr [$time_local] '
'$protocol $status $bytes_sent $bytes_received '
'$session_time "$upstream_addr" '
'"$upstream_bytes_sent" "$upstream_bytes_received" "$upstream_connect_time"';
upstream mysql {
server 172.16.100.10:3306 weight=1 max_fails=3 fail_timeout=30s;
server 172.16.100.11:3306 weight=1 max_fails=3 fail_timeout=30s;
server 172.16.100.12:3306 weight=1 max_fails=3 fail_timeout=30s;
}
server {
listen 3306;
proxy_connect_timeout 2s;
proxy_timeout 900s;
proxy_pass mysql;
access_log /dev/stdout main;
}
}