nginx 配置4层代理

栏目: 服务器 · Nginx · 发布时间: 5年前

内容简介:nginx-1.9.0 开始支持 TCP 代理,也就是4层代理,默认编译不会支持,需要加上 –with-stream 参数编译。进入 nginx 目录编译

nginx-1.9.0 开始支持 TCP 代理,也就是4层代理,默认编译不会支持,需要加上 –with-stream 参数编译。

NGINX 编译

进入 nginx 目录

cd /home/fwj/nginx-1.15.9

编译

./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre --with-stream

配置 nginx.conf

user  www www;
worker_processes  1;


events {
    worker_connections  1024;
}

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"';
    open_log_file_cache off;
    access_log logs/tcp-access.log proxy ;
    upstream test{
        server 127.0.0.1:666  weight=1 max_fails=1 fail_timeout=30s;
    }
    server{
        listen 60;
        proxy_pass test;
        proxy_connect_timeout 8s;
        proxy_timeout 7d;
    }
}

执行

./nginx -c /usr/local/nginx/conf/nginx.conf

查看日志

# cat tcp-access.log
192.168.10.202 [06/Mar/2019:12:35:30 +0800] TCP 200 615 749 5.170 "127.0.0.1:666" "749" "615" "0.000"
192.168.10.202 [06/Mar/2019:12:36:07 +0800] TCP 200 246 419 5.008 "127.0.0.1:666" "419" "246" "0.000"
192.168.10.202 [06/Mar/2019:12:38:50 +0800] TCP 200 0 0 0.000 "127.0.0.1:666" "0" "0" "0.000"

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

高效程序员的45个习惯

高效程序员的45个习惯

Venkat Subramaniam、Andy Hunt / 钱安川、郑柯 / 人民邮电出版社 / 2010-01 / 35.00元

“书中‘切身感受’的内容非常有价值——通过它我们可以做到学有所思,思有所悟,悟有所行。” ——Nathaniel T. Schutta,《Ajax基础教程》作者 “此书通过常理和经验,阐述了为什么你应该在项目中使用敏捷方法。最难得的是,这些行之有效的实战经验,竟然从一本书中得到了。” ——Matthew Johnson,软件工程师 十年来,软件行业发生了翻天覆地的变化。敏捷......一起来看看 《高效程序员的45个习惯》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

随机密码生成器
随机密码生成器

多种字符组合密码

URL 编码/解码
URL 编码/解码

URL 编码/解码