Nginx TCP代理
生活随笔
收集整理的這篇文章主要介紹了
Nginx TCP代理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
nginx 在1.9.0 版本發布以前如果要想做到基于TCP的代理及負載均衡需要通過打名為nginx_tcp_proxy_module的第三方patch來實現,該模塊的代碼托管在github上 網址:https://github.com/yaoweibin/nginx_tcp_proxy_module/,而我們今年要來簡單測試一下nginx 的ngx_stream_core_module,該模塊有nginx 官方發布并支持tcp代理及負載均衡。
?
ngx_stream_core_module 這個模塊在1.90版本后將被啟用。但是并不會默認安裝,需要在編譯時通過指定?--with-stream 參數來激活這個模塊。
其他改進包括:
- Change: 刪除過時的 aio 和 rtsig 事件處理方法
- Feature: 可在 upstream 塊中使用 "zone" 指令
- Feature: 流模塊,支持 TCP 代理和負載均衡
- Feature: ngx_http_memcached_module 支持字節范圍
- Feature: Windows 版本支持使用共享內存,帶隨機化地址空間布局.
- Feature: "error_log" 指令可在 mail 和 server 級別
- Bugfix: the "proxy_protocol" parameter of the "listen" directive did?not work if not specified in the first "listen" directive for a?listen socket.
簡單配置步驟如下(測試MYSQL負載):
wget http://nginx.org/download/nginx-1.9.3.tar.gz tar zxvf nginx-1.9.3.tar.gz cd nginx-1.9.3yum -y install proc* yum -y install openssl* yum -y install pcre*./configure --prefix=/usr/local/nginx-1.9.3_tcp \ --with-http_ssl_module --with-http_spdy_module \ --with-http_stub_status_module --with-pcre \ --with-streamcd /usr/local/nginx-1.9.3_tcp/conf/ mv nginx.conf{,.bak} vim nginx.confworker_processes auto; events {worker_connections 1024; } error_log /var/log/nginx_error.log info; stream {upstream mysqld {hash $remote_addr consistent;server 192.168.1.42:3306 weight=5 max_fails=1 fail_timeout=10s;server 192.168.1.43:3306 weight=5 max_fails=1 fail_timeout=10s;}server {listen 3306;proxy_connect_timeout 1s;proxy_timeout 3s;proxy_pass mysqld;}}另外還可以實現一個ssh 轉發代理
upstream ssh {hash $remote_addr consistent;server 192.168.1.42:22 weight=5;} server {listen 2222;proxy_pass ssh; }?
參考:
http://zhangge.net/5037.html
http://nginx.org/en/docs/stream/ngx_stream_core_module.html
轉載于:https://www.cnblogs.com/storymedia/p/4667246.html
總結
以上是生活随笔為你收集整理的Nginx TCP代理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 它们的定义app.config中间sec
- 下一篇: JMeter压力测试入门教程[图文]