【转】Nginx实现TCP反向代理
Nginx在1.9.0版本发布以前如果要想做到基于TCP的代理及负载均衡需要通过打名为nginx_tcp_proxy_module的第三方patch来实现,该模块的代码托管在github上网址:https://github.com/yaoweibin/nginx_tcp_proxy_module/
Nginx从1.9.0开始发布ngx_stream_core_module模块,该模块支持tcp代理及负载均衡。
安装Nginx并启用模块
ngx_stream_core_module这个模块并不会默认启用,需要在编译时通过指定--with-stream参数来激活这个模块。
- 编译安装
$ yum -y install proc* openssl* pcre* $ wget http://nginx.org/download/nginx-1.9.4.tar.gz $ tar zxvf nginx-1.9.4.tar.gz $ cd nginx-1.9.4 $ ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-threads --with-stream --with-stream_ssl_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' $ make $ make install
- 配置stream模块
例子:配置应用的反向代理和负载均衡
user shuke; worker_processes 16; error_log logs/error.log; error_log logs/error.log notice; error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 4096; } stream { upstream client{ server 192.168.1.42:18334; server 192.168.1.43:18334; } upstream admin{ server 192.168.1.42:18335; server 192.168.1.43:18335; } server { listen 18111; proxy_pass client; } server { listen 18112; proxy_pass admin; } }
转载自《现在使用Nginx实现TCP反向代理》
それでも私の大好きな人
【推荐】100%开源!大型工业跨平台软件C++源码提供,建模,组态!
【推荐】AI 的力量,开发者的翅膀:欢迎使用 AI 原生开发工具 TRAE
【推荐】2025 HarmonyOS 鸿蒙创新赛正式启动,百万大奖等你挑战
· 当加密ID需要变成Guid:为什么我选择了AES-CBC而非GCM?
· 基于 epoll 的协程调度器——零基础深入浅出 C++20 协程
· 下划线字段在golang结构体中的应用
· SQL Server也能玩正则表达式?
· CUDA 编程初探
· 家里有密码锁的注意了,这真不是 BUG,是 feature。
· C#实现屏幕墙:同时监控多个电脑桌面(支持Windows、信创Linux、银河麒麟、统信UOS)
· 直击痛点的开源项目「GitHub 热点速览」
· C# 13 与 .NET 9 跨平台开发实战(第一章:开发环境搭建与.NET概述-上篇)
· 我的AI自学路线,可能对你有用
2017-01-04 【转】Windows下使用libsvm中的grid.py和easy.py进行参数调优