zoukankan      html  css  js  c++  java
  • 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才会将相关日志记录到指定的日志文件中

  • 相关阅读:
    C语言超大数据相加计算整理
    pc端页面加载更多条信息(loading)
    web前端学习路线
    linux启动流程
    Computer Science: http://www.cs.odu.edu/~cs779/
    编程网站
    sublime-text 键绑定
    monokai-background
    .vimrc
    vim 正则表达式查找ip
  • 原文地址:https://www.cnblogs.com/fat-girl-spring/p/13898846.html
Copyright © 2011-2022 走看看