1、socket使用的是TCP/IP协议,编译安装nginx必须启用--with-stream模块。在stream中配置请求转发
./configure [--prefix=/usr/local/nginx:指定安装目录】 --with-stream
make
make install
2、在配置文件nginx.conf中加stream模块
worker_processes 1;
events {
worker_connections 1024;
}
# 此为TCP转发请求 stream
stream {
log_format proxy '$remote_addr - [$time_local] '
'$protocol $status $bytes_sent $bytes_received '
'$session_time "$upstream_addr" '
'"$upstream_bytes_sent" "$upstream_bytes_received"
"$upstream_connect_time" '
'$remote_addr $remote_port $server_addr $server_port';
include ./conf.d/*.tcpstream;
# 后端指向 server 的 8085 端口 stream_backend 组
upstream stream_backend {
server 10.50.2.11:8085;
server 10.50.2.19:8085;
}
# 后端指向 server 的 8090 端口 cns组
ups