Mercurial > hg > nginx-site
view xml/en/docs/stream/ngx_stream_core_module.xml @ 1530:2db1dc7cc1a3
Updated with Netcraft June 2015 Web Server Survey stats.
author | Yaroslav Zhuravlev <yar@nginx.com> |
---|---|
date | Mon, 06 Jul 2015 19:14:19 +0300 |
parents | 3ae5301ea37a |
children | 8ea1813272bb |
line wrap: on
line source
<?xml version="1.0"?> <!-- Copyright (C) Nginx, Inc. --> <!DOCTYPE module SYSTEM "../../../../dtd/module.dtd"> <module name="Module ngx_stream_core_module" link="/en/docs/stream/ngx_stream_core_module.html" lang="en" rev="9"> <section id="summary"> <para> The <literal>ngx_stream_core_module</literal> module is available since version 1.9.0. This module is not built by default, it should be enabled with the <literal>--with-stream</literal> configuration parameter. </para> </section> <section id="example" name="Example Configuration"> <para> <example> 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; } server { listen 12345; proxy_connect_timeout 1s; proxy_timeout 3s; proxy_pass backend; } server { listen [::1]:12345; proxy_pass unix:/tmp/stream.socket; } } </example> </para> </section> <section id="directives" name="Directives"> <directive name="listen"> <syntax> <value>address</value>:<value>port</value> [<literal>ssl</literal>] [<literal>backlog</literal>=<value>number</value>] [<literal>bind</literal>] [<literal>ipv6only</literal>=<literal>on</literal>|<literal>off</literal>] [<literal>reuseport</literal>] [<literal>so_keepalive</literal>=<literal>on</literal>|<literal>off</literal>|[<value>keepidle</value>]:[<value>keepintvl</value>]:[<value>keepcnt</value>]]</syntax> <default/> <context>server</context> <para> Sets the <value>address</value> and <value>port</value> for the socket on which the server will accept connections. It is possible to specify just the port. The address can also be a hostname, for example: <example> listen 127.0.0.1:12345; listen *:12345; listen 12345; # same as *:12345 listen localhost:12345; </example> IPv6 addresses are specified in square brackets: <example> listen [::1]:12345; listen [::]:12345; </example> UNIX-domain sockets are specified with the “<literal>unix:</literal>” prefix: <example> listen unix:/var/run/nginx.sock; </example> </para> <para> The <literal>ssl</literal> parameter allows specifying that all connections accepted on this port should work in SSL mode. </para> <para> The <literal>listen</literal> directive can have several additional parameters specific to socket-related system calls. <list type="tag"> <tag-name> <literal>backlog</literal>=<value>number</value> </tag-name> <tag-desc> sets the <literal>backlog</literal> parameter in the <c-func>listen</c-func> call that limits the maximum length for the queue of pending connections (1.9.2). By default, <literal>backlog</literal> is set to -1 on FreeBSD, DragonFly BSD, and Mac OS X, and to 511 on other platforms. </tag-desc> <tag-name> <literal>bind</literal> </tag-name> <tag-desc> this parameter instructs to make a separate <c-func>bind</c-func> call for a given address:port pair. The fact is that if there are several <literal>listen</literal> directives with the same port but different addresses, and one of the <literal>listen</literal> directives listens on all addresses for the given port (<literal>*:</literal><value>port</value>), nginx will <c-func>bind</c-func> only to <literal>*:</literal><value>port</value>. It should be noted that the <c-func>getsockname</c-func> system call will be made in this case to determine the address that accepted the connection. If the <literal>ipv6only</literal> or <literal>so_keepalive</literal> parameters are used then for a given <value>address</value>:<value>port</value> pair a separate <c-func>bind</c-func> call will always be made. </tag-desc> <tag-name> <literal>ipv6only</literal>=<literal>on</literal>|<literal>off</literal> </tag-name> <tag-desc> this parameter determines (via the <c-def>IPV6_V6ONLY</c-def> socket option) whether an IPv6 socket listening on a wildcard address <literal>[::]</literal> will accept only IPv6 connections or both IPv6 and IPv4 connections. This parameter is turned on by default. It can only be set once on start. </tag-desc> <tag-name id="reuseport"> <literal>reuseport</literal> </tag-name> <tag-desc> this parameter (1.9.1) instructs to create an individual listening socket for each worker process (using the <c-def>SO_REUSEPORT</c-def> socket option), allowing a kernel to distribute incoming connections between worker processes. This currently works only on Linux 3.9+ and DragonFly BSD. <note> Inappropriate use of this option may have its security <link url="http://man7.org/linux/man-pages/man7/socket.7.html">implications</link>. </note> </tag-desc> <tag-name> <literal>so_keepalive</literal>=<literal>on</literal>|<literal>off</literal>|[<value>keepidle</value>]:[<value>keepintvl</value>]:[<value>keepcnt</value>] </tag-name> <tag-desc> this parameter configures the “TCP keepalive” behavior for the listening socket. If this parameter is omitted then the operating system’s settings will be in effect for the socket. If it is set to the value “<literal>on</literal>”, the <c-def>SO_KEEPALIVE</c-def> option is turned on for the socket. If it is set to the value “<literal>off</literal>”, the <c-def>SO_KEEPALIVE</c-def> option is turned off for the socket. Some operating systems support setting of TCP keepalive parameters on a per-socket basis using the <c-def>TCP_KEEPIDLE</c-def>, <c-def>TCP_KEEPINTVL</c-def>, and <c-def>TCP_KEEPCNT</c-def> socket options. On such systems (currently, Linux 2.4+, NetBSD 5+, and FreeBSD 9.0-STABLE), they can be configured using the <value>keepidle</value>, <value>keepintvl</value>, and <value>keepcnt</value> parameters. One or two parameters may be omitted, in which case the system default setting for the corresponding socket option will be in effect. For example, <example>so_keepalive=30m::10</example> will set the idle timeout (<c-def>TCP_KEEPIDLE</c-def>) to 30 minutes, leave the probe interval (<c-def>TCP_KEEPINTVL</c-def>) at its system default, and set the probes count (<c-def>TCP_KEEPCNT</c-def>) to 10 probes. </tag-desc> </list> </para> <para> Different servers must listen on different <value>address</value>:<value>port</value> pairs. </para> </directive> <directive name="resolver"> <syntax> <value>address</value> ... [<literal>valid</literal>=<value>time</value>] [<literal>ipv6</literal>=<literal>on</literal>|<literal>off</literal>]</syntax> <default/> <context>stream</context> <context>server</context> <para> Configures name servers used to resolve names of upstream servers into addresses, for example: <example> resolver 127.0.0.1 [::1]:5353; </example> An address can be specified as a domain name or IP address, and an optional port. If port is not specified, the port 53 is used. Name servers are queried in a round-robin fashion. </para> <para> By default, nginx will look up both IPv4 and IPv6 addresses while resolving. If looking up of IPv6 addresses is not desired, the <literal>ipv6=off</literal> parameter can be specified. </para> <para> By default, nginx caches answers using the TTL value of a response. The optional <literal>valid</literal> parameter allows overriding it: <example> resolver 127.0.0.1 [::1]:5353 valid=30s; </example> <note> This directive is available as part of our <commercial_version>commercial subscription</commercial_version>. </note> </para> </directive> <directive name="resolver_timeout"> <syntax><value>time</value></syntax> <default>30s</default> <context>stream</context> <context>server</context> <para> Sets a timeout for name resolution, for example: <example> resolver_timeout 5s; </example> <note> This directive is available as part of our <commercial_version>commercial subscription</commercial_version>. </note> </para> </directive> <directive name="server"> <syntax block="yes"/> <default/> <context>stream</context> <para> Sets the configuration for a server. </para> </directive> <directive name="stream"> <syntax block="yes"/> <default/> <context>main</context> <para> Provides the configuration file context in which the stream server directives are specified. </para> </directive> </section> </module>