Discussion on Nginx stream module

Source: Internet
Author: User
Tags iso 8601 server port
Preface

Nginx starting from 1.9.0, a new stream module is added to implement four-layer protocol forwarding, proxy or load balancing. This is exactly the pace of haproxy share, given Nginx's success in 7-tier load balancing and Web service, and nginx good framework, the stream module has a bright future. Stream Module Compilation

Stream module default is not compiled to Nginx, compile nginx time./configure–with-stream can

Official website: http://nginx.org/en/docs/stream/ngx_stream_core_module.html usage

The stream module usage is similar to the HTTP module, and the key is that the syntax is almost identical. Familiarity with HTTP module configuration syntax is faster
Here's an example of TCP load balancing and UDP (DNS) load balancing, with Server,upstream blocks, and the server,
Hash, listen, proxy_pass and other instructions, if not look at the outermost stream keyword, but also thought is the HTTP module.

Worker_processes Auto;
Error_log Logs/error.stream.log info;
Events {
    worker_connections  1024;
}
Stream {
    Upstream backend {
        hash $remote _addr consistent;
        Server 127.0.0.1:12346 weight=5;
        Server 127.0.0.1:12347            max_fails=3 fail_timeout=30s;
        Server 127.0.0.1:12348            max_fails=3 fail_timeout=30s;
    }
    Upstream DNS {
       server 17.61.29.79:53;
       Server 17.61.29.80:53;
       Server 17.61.29.81:53;
       Server 17.61.29.82:53;
    }
    server {
        listen 12345;
        Proxy_connect_timeout 1s;
        Proxy_timeout 3s;
        Proxy_pass backend;
    }
    server {
        listen 127.0.0.1:53 UDP;
        Proxy_responses 1;
        Proxy_timeout 20s;
        Proxy_pass DNS;
    }
}
Stream Core Some variables

NOTE: Variable support starts with the Nginx version 1.11.2

$binary The
client address in _remote_addr binary format $bytes _received the number of bytes
received from the client
$bytes _sent
Bytes sent to the client
$ Hostname
The current time $msec millisecond precision of the connection domain name
$nginx _version
nginx version
$pid
worker process number
$ Protocol
Communication Protocol (UDP or TCP)
$remote _addr
client IP
$remote _port
client port
$server _addr
The server IP that accepts the connection, the calculation of this variable requires a system call. So avoid system calls, you must specify a specific server address in the Listen directive and use parameter bind.
$server _port The
server port that accepts the connection
$session _time
The session time of the millisecond precision (version 1.11.4 start)
$status
Session state (version 1.11.4 start), can be a few values:
success
does not normally resolve client data
403
prohibit access to
server internal errors
502
Gateway error, such as the upstream server could not connect
503
service is not available, such as due to restrictions on connectivity and other measures resulting in
$time _iso8601
ISO 8601 time format
$ Time_local
the regular log format timestamp
Stream Module

At present, the third party module listed on the official Internet is simply mirroring the HTTP module, such as Access module accessing control IP and IP segment, map module implementation mapping, GEO module to achieve geographic mapping, etc. Use these modules must see which version is supported, such as log module, only in nginx-1.11.4 support.

ngx_stream_core_module ngx_stream_access_module ngx_stream_geo_module Ngx_stream_geoip_ Module Ngx_stream_js_module ngx_stream_limit_conn_module ngx_stream_log_module ngx_stream_map_module NGX_STREAM_ Proxy_module ngx_stream_realip_module ngx_stream_return_module ngx_stream_split_clients_module ngx_stream_ssl_ Module Ngx_stream_ssl_preread_module ngx_stream_upstream_module ngx_stream_upstream_hc_module 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.