nginx安装 略 (注意:必须加上--with-stream这个模块)
修改nginx.conf:
user www www; worker_processes 4; pid logs/nginx.pid; events { #use epoll; #Linux最常用支持大并发的事件触发机制 worker_connections 65535; } 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"'; access_log logs/access_8000.log proxy ; open_log_file_cache off; upstream zifangsky { #hash $remote_addr consistent; server 10.10.100.31:8000 weight=5 max_fails=1 fail_timeout=20s; } server { listen 8000; proxy_connect_timeout 10s; proxy_timeout 10s; proxy_pass zifangsky; tcp_nodelay on; } }
在上面的配置文件中配置了在访问此服务器的8080端口时,会将流量相应转发到10.10.100.31这个服务器的8000端口上。另外,测试发现只有当一个会话结束之后nginx才会将相关日志记录到指定的日志文件中