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才會將相關日志記錄到指定的日志文件中