• NGINX 做TCP转发(端口转发)并记录日志


    nginx安装 略 (注意:必须加上--with-stream这个模块)

    修改nginx.conf:

    user  www www;
    worker_processes  4; 
    pid        logs/nginx.pid;
     
    events {
        #use epoll;                            #Linux最常用支持大并发的事件触发机制
        worker_connections  65535;
    }
     
    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"';
     
        access_log logs/access_8000.log proxy ;
        open_log_file_cache off;
        
        upstream zifangsky {
            #hash $remote_addr consistent;
            server 10.10.100.31:8000 weight=5 max_fails=1 fail_timeout=20s;
        }
     
        server {
            listen 8000;
            proxy_connect_timeout 10s;
            proxy_timeout 10s;
            proxy_pass zifangsky;
        tcp_nodelay on;
        }
    }

    在上面的配置文件中配置了在访问此服务器的8080端口时,会将流量相应转发到10.10.100.31这个服务器的8000端口上。另外,测试发现只有当一个会话结束之后nginx才会将相关日志记录到指定的日志文件中

  • 相关阅读:
    多态
    封装,继承,多态
    基本类型和引用类型的区别
    第七天 面向对象
    什么是Java线程池
    游戏内核架构
    放松
    静不下来心写代码
    速度和正确率
    理顺思路
  • 原文地址:https://www.cnblogs.com/fat-girl-spring/p/13898846.html
Copyright © 2020-2023  润新知