Nginx1.9 版本以后增加 stream模块,可以对tcp,udp请求进行代理和负载均衡了
1、安装
yum -y install pcre-devel
wget http://nginx.org/download/nginx-1.12.1.tar.gz
tar zxf nginx-1.12.1.tar.gz
cd nginx-1.12.1
./configure --prefix=/usr/local/nginx --with-stream --with-stream_ssl_module
make
make install
2、配置
#vim /usr/local/nginx/conf/nginx.conf
worker_processes auto;
error_log /usr/local/nginx/logs/error.log error;
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 backend {
#hash $remote_addr consistent;
least_conn;
server 127.0.0.8:50179;
server 127.0.0.9:50179;
server 127.0.0.248:50179;
server 127.0.0.249:50179;
server 127.0.0.32:50179;
server 127.0.0.33:50179;
server 127.0.0.34:50179;
server 127.0.0.35:50179;
server 127.0.0.36:50179;
server 127.0.0.8:50179;
}
server {
listen 1080;
access_log /usr/local/nginx/logs/access.log main;
proxy_pass backend;
}
}
3、启动:
/usr/local/nginx/sbin/nginx
原文地址:http://blog.51cto.com/13718151/2107254
时间: 2024-10-28 08:16:38