nginx 配置4层代理

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

内容简介: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"

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

查看所有标签

猜你喜欢:

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

Programming Ruby

Programming Ruby

Dave Thomas、Chad Fowler、Andy Hunt / Pragmatic Bookshelf / 2004-10-8 / USD 44.95

Ruby is an increasingly popular, fully object-oriented dynamic programming language, hailed by many practitioners as the finest and most useful language available today. When Ruby first burst onto the......一起来看看 《Programming Ruby》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具