标签:
nginx tcp代理功能由nginx_tcp_proxy_module模块提供,同时监测后端主机状态。该模块包括的模块有: ngx_tcp_module, ngx_tcp_core_module, ngx_tcp_upstream_module, ngx_tcp_proxy_module, ngx_tcp_upstream_ip_hash_module。
安装
https://github.com/yaoweibin/nginx_tcp_proxy_module/archive/master.zip unzip master.zip cd nginx-1.6.2 patch -p1 < /data/tools/nginx_tcp_proxy_module-master/tcp.patch ./configure --prefix=/data/program/nginx --add-module=/data/tools/nginx_tcp_proxy_module-master/ --with-http_ssl_module make && make install
配置
more /data/program/nginx/conf/vhost/payment.test tcp { timeout 1d; proxy_read_timeout 10d; proxy_send_timeout 10d; proxy_connect_timeout 30; upstream cluster_test { server 127.0.0.1:9991; check interval=3000 rise=2 fall=5 timeout=1000; } server { listen 8080; proxy_pass cluster_test; so_keepalive on; tcp_nodelay on; } }
注意nginx.conf
more /data/program/nginx/conf/nginx.conf user nginx; worker_processes 4; error_log logs/error.log; #pid logs/nginx.pid; worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; limit_conn_zone $server_name zone=perserver:10m; log_format main ‘$remote_addr - $remote_user [$time_local] "$request" ‘ ‘$status $body_bytes_sent "$http_referer" ‘ ‘"$http_user_agent" ‘; sendfile on; tcp_nopush on; #keepalive_timeout 0; #keepalive_timeout 65; tcp_nodelay on; server_tokens off; client_max_body_size 30m; underscores_in_headers on; keepalive_timeout 60; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; fastcgi_intercept_errors on; #cache setting gzip on; gzip_proxied any; gzip_comp_level 5; gzip_min_length 1024; gzip_vary on; gzip_buffers 4 8k; gzip_http_version 1.1; gzip_types text/plain text/css application/x-javascript. text/xml application/xml application/xml+rss text/javascript ; #limit_zone myzone $binary_remote_addr 10m; include vhost/*.conf; } include vhost/payment.test; ####################################################这一行要特别注意,tcp的配置是不能写进http里面的
这样就完成了nginx的tcp负载,nginx可以用在不止是7层哦
文章参考:http://www.ttlsa.com/nginx/nginx-tcp-proxy/
nginx tcp代理模块nginx_tcp_proxy_module
标签:
原文地址:http://my.oschina.net/jastme/blog/494724