ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

nginx使用4层模式(tcp)ip透传到应用

2022-06-01 10:32:45  阅读:202  来源: 互联网

标签:http stream -- ip module nginx tcp upstream


1,nginx编译安装时要加上stream模块里的--with-stream --with-stream_realip_module,第一个用来四层负载,第二个用来获得客户端真实IP地址

[root@localhost ~]# nginx -V

nginx version: nginx/1.14.0

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) 

built with OpenSSL 1.0.2o  27 Mar 2018

TLS SNI support enabled

configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-stream --with-stream_realip_module --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-1.0.2o --with-pcre=../pcre-8.42 --with-pcre-jit --with-ld-opt=-ljemalloc --add-module=./nginx_upstream_check_module-master

 

2,Nginx加入主配置文件4层的配置nginx.conf

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"';

    include vhost/*.stream;

}

 

3,具体配置文件的写法

upstream test9001 {

        server 192.168.0.1:9001 weight=1 max_fails=3 fail_timeout=30s;   #负载

    }

server {

        listen 9001;   #监听端口

        set_real_ip_from 10.3.0.0/24;    #上一层代理IP地址

        proxy_protocol on;   #打开代理协议

        proxy_pass test9001;

        proxy_connect_timeout 600;

        access_log /data/wwwlogs/test.log proxy;

        error_log /data/wwwlogs/test.error.log error;

       }
-----------------------------------
©著作权归作者所有:来自51CTO博客作者wx5a9e3b462cab6的原创作品,请联系作者获取转载授权,否则将追究法律责任
nginx使用4层模式(tcp)ip透传到应用
https://blog.51cto.com/u_13628717/4567630

标签:http,stream,--,ip,module,nginx,tcp,upstream
来源: https://www.cnblogs.com/netflix/p/16333402.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有