zoukankan      html  css  js  c++  java
  • Nginx 4层*

    L112

    是基于TCP

    POST_ACCEPT阶段 在建立连接后所做的事情 

    PREACCESS阶段  limit_conn 限流 与HTTP类似

    ACCESS阶段 类似HTTP模块用于控制访问权限

    SSL阶段  ssl请求

    PREREAD阶段 ssl_preread 从头部取信息

    CONTENT阶段 return,stream_proxy

    LOG阶段 类似http log阶段

    Syntax: stream { ... } 提供指定流服务器指令的配置文件上下文
    Default:
    Context: main
    Syntax: server { ... }
    Default:
    Context: stream
    Syntax: listen address:port [ssl] [udp] [proxy_protocol] [backlog=number] [rcvbuf=size] [sndbuf=size] [bind] [ipv6only=on|off] [reuseport] [so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]];
    Default:
    Context: server

    模块 ngx_stream_return_module

    Syntax: return value;
    Default:
    Context: server

    需要编译进Nginx

    http://nginx.org/en/docs/stream/ngx_stream_core_module.html

    可以用 telnet 192.168.1.1 10004 方式查看数据

    worker_processes auto;
    
    error_log /var/log/nginx/error.log info;
    
    events {
        worker_connections  1024;
    }
    
    stream {
        upstream backend {
            hash $remote_addr consistent;
    
            server backend1.example.com:12345 weight=5;
            server 127.0.0.1:12345            max_fails=3 fail_timeout=30s;
            server unix:/tmp/backend3;
        }
    
        upstream dns {
           server 192.168.0.1:53535;
           server dns.example.com:53;
        }
    
        server {
            listen 12345;
            proxy_connect_timeout 1s;
            proxy_timeout 3s;
            proxy_pass backend;
        }
    
        server {
            listen 127.0.0.1:53 udp reuseport;
            proxy_timeout 20s;
            proxy_pass dns;
        }
    
        server {
            listen [::1]:12345;
            proxy_pass unix:/tmp/stream.socket;
        }
    }

    代码示列

    stream {
        log_format basic '$remote_addr [$time_local] '
                     '$protocol $status $bytes_sent $bytes_received '
                     '$session_time';
    
        error_log logs/stream_error.log debug;
        access_log logs/stream_access.log basic;
        server {
            listen 10002 proxy_protocol;
            return '10002 server get ip: $remote_addr!
    ';
        }
    
        server {
            listen 10003 proxy_protocol;
            return '10003 server get ip: $remote_addr!
    ';
            }
    
        server {
            #listen 10004;
            listen 10004 proxy_protocol;
            set_real_ip_from 127.0.0.1;
            allow 202.112.144.236;
            deny all;
            return '10004 vars:
    bytes_received: $bytes_received
    bytes_sent: $bytes_sent
    proxy_protocol_addr: $proxy_protocol_addr
    proxy_protocol_port: $proxy_protocol_port
    remote_addr: $remote_addr
    remote_port: $remote_port
    realip_remote_addr: $realip_remote_addr
    realip_remote_port: $realip_remote_port
    server_addr: $server_addr
    server_port: $server_port
    session_time: $session_time
    status: $status
    protocol: $protocol
    ';
        }
    }
  • 相关阅读:
    LeetCode: Reverse Linked List
    DataBase: MySQL在.NET中的应用
    DataBase: LeetCode
    DirectShow+VS2010+Win7配置说明
    MathType应用:批量改变公式格式
    $LaTeX$笔记:首字下沉
    Latex学习笔记-序
    反思--技术博客的写作应该是怎样的?
    用Latex写学术论文:作者(Author)&摘要(Abstract)
    用Latex写学术论文: IEEE Latex模板和文档设置(documentclass)
  • 原文地址:https://www.cnblogs.com/jackey2015/p/10566415.html
Copyright © 2011-2022 走看看