国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > Nginx > 正文

nginx搭建tcp代理服務器

2024-08-30 12:22:05
字體:
來源:轉載
供稿:網友
Nginx 超越 Apache 的高性能和穩定性,使得國內使用 Nginx 作為 Web 服務器的網站也越來越多,大部分門戶網站都把它作為首選WEB前端。下面講講如何利用Nginx搭建tcp代理服務器

nginx不僅可以是http代理服務器,也可以輕松搭建成tcp代理服務器。

首先我們看下最新開發版的搭建方法

1. 安裝

> wget http://nginx.org/download/nginx-1.9.0.tar.gz> tar zxvf nginx-1.9.0.tar.gz

版本要求 1.9.0+

2、配置

worker_processes auto;error_log /var/log/nginx/error.log info;stream {  upstream backend {    hash $remote_addr consistent;    server backend1.example.com:12345 weight=5;    server 127.0.0.1:12345      max_fails=3 fail_timeout=30s;    server unix:/tmp/backend3;  }  server {    listen 12345;    proxy_connect_timeout 1s;    proxy_timeout 3s;    proxy_pass backend;  }  server {    listen [::1]:12345;    proxy_pass unix:/tmp/stream.socket;  }}

3. 補充
現在nginx 1.9是開發版,目前穩定版沒有stream的功能,但在下個的穩定版發布時,這功能就會集成進來。因此推薦以后用http proxy的同學可以考慮換成tcp proxy,如果只是做簡單的代理而已,而且性能上會更優異。

二、老版本的搭建方法

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。
1. 安裝

# wget http://nginx.org/download/nginx-1.4.4.tar.gz# tar zxvf nginx-1.4.4.tar.gz# cd nginx-1.4.4# ./configure --add-module=/path/to/nginx_tcp_proxy_module# make# make install

2. 配置

http {  listen 80;  location /status {    check_status;  }}tcp {  upstream cluster_www_ttlsa_com {    # simple round-robin    server 127.0.0.1:1234;    check interval=3000 rise=2 fall=5 timeout=1000;    #check interval=3000 rise=2 fall=5 timeout=1000 type=ssl_hello;    #check interval=3000 rise=2 fall=5 timeout=1000 type=http;    #check_http_send "GET / HTTP/1.0/r/n/r/n";    #check_http_expect_alive http_2xx http_3xx;  }  server {    listen 8888;    proxy_pass cluster_www_ttlsa_com;  }}

這會出現一個問題,就是tcp連接會掉線。原因在于當服務端關閉連接的時候,客戶端不可能立刻發覺連接已經被關閉,需要等到當Nginx在執行check規則時認為服務端鏈接關閉,此時nginx會關閉與客戶端的連接。

3. 保持連接配置

http {  listen 80;  location /status {    check_status;  }}tcp { timeout 1d;  proxy_read_timeout 10d;  proxy_send_timeout 10d;  proxy_connect_timeout 30;  upstream cluster_www_ttlsa_com {    # simple round-robin    server 127.0.0.1:1234;    check interval=3000 rise=2 fall=5 timeout=1000;    #check interval=3000 rise=2 fall=5 timeout=1000 type=ssl_hello;    #check interval=3000 rise=2 fall=5 timeout=1000 type=http;    #check_http_send "GET / HTTP/1.0/r/n/r/n";    #check_http_expect_alive http_2xx http_3xx;  }  server {    listen 8888;    proxy_pass cluster_www_ttlsa_com; so_keepalive on;    tcp_nodelay on;  }}
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 长宁区| 建平县| 汤原县| 中超| 湛江市| 洞口县| 太谷县| 泽普县| 神池县| 浑源县| 寿宁县| 丹江口市| 含山县| 烟台市| 治多县| 阜康市| 日土县| 肇庆市| 赞皇县| 正安县| 常德市| 东丰县| 中阳县| 小金县| 双辽市| 鄂伦春自治旗| 德昌县| 鄂尔多斯市| 忻城县| 宝山区| 土默特右旗| 南川市| 丰都县| 临桂县| 邵武市| 玛纳斯县| 大邑县| 乌鲁木齐县| 孝感市| 临潭县| 浑源县|