Code Monkey home page Code Monkey logo

nginx_tcp_proxy_module's Introduction

Name

nginx_tcp_proxy_module - support TCP proxy with Nginx

Installation

Download the latest stable version of the release tarball of this module from github (http://github.com/yaoweibin/nginx_tcp_proxy_module)

Grab the nginx source code from nginx.org (http://nginx.org/), for example, the version 1.20.2 (see nginx compatibility), and then build the source with this module:

$ wget 'http://nginx.org/download/nginx-1.20.2.tar.gz'
$ tar -xzvf nginx-1.20.2.tar.gz
$ cd nginx-1.20.2/
$ patch -p1 < /path/to/nginx_tcp_proxy_module/tcp.patch

$ ./configure --add-module=/path/to/nginx_tcp_proxy_module

$ make
$ make install

Synopsis

    http {
        server {
            listen 80;
    
            location /status {
                tcp_check_status;
            }
        }
    }
    #You can also include tcp_proxy.conf file individually
    #include /path/to/tcp_proxy.conf;
    tcp {
        upstream cluster {
            # simple round-robin
            server 192.168.0.1:80;
            server 192.168.0.2:80;
    		
            check interval=3000 rise=2 fall=5 timeout=1000;
    		
            #check interval=3000 rise=2 fall=5 timeout=1000 type=ssl_hello;
    
            #check interval=3000 rise=2 fall=5 timeout=1000 type=http;
            #check_http_send "GET / HTTP/1.0\r\n\r\n";
            #check_http_expect_alive http_2xx http_3xx;
        }
    
        server {
            listen 8888;
            ...
            proxy_pass cluster;
        }
    }

Description

This module actually include many modules:

ngx_tcp_module,
ngx_tcp_core_module, 
ngx_tcp_upstream_module, 
ngx_tcp_proxy_module,
ngx_tcp_websocket_module, 
ngx_tcp_ssl_module,
ngx_tcp_upstream_ip_hash_module

All these modules work together to support TCP proxy with Nginx. I also added other features:

ip_hash,
upstream server health check,
status monitor

The motivation of writing these modules is Nginx's high performance and robustness. At first, I developed this module just for general TCP proxy. And now, this module is frequently used in websocket reverse proxying.

Note, You can't use the same listening port with HTTP modules.

Directives

ngx_tcp_module

tcp

syntax: tcp {...}
default: none
context: main
description: All the tcp related directives are contained in the tcp block.

ngx_tcp_core_module

server

syntax: server {...}
default: none
context: tcp
description: All the specific server directives are contained in the server block.

listen

syntax: listen address:port [ bind | ssl | default]
default: none
context: server
description: The same as listen (http://wiki.nginx.org/NginxMailCoreModule#listen). The parameter of
default means the default server if you have several server blocks with the same port.

access_log

syntax: access_log path [buffer=size] | off
default: access_log logs/tcp_access.log
context: tcp, server
description: Set the access.log. Each record's format is like this:

log_time worker_process_pid client_ip host_ip accept_time upstream_ip
bytes_read bytes_write

2011/08/02 06:19:07 [5972] 127.0.0.1 0.0.0.0:1982 2011/08/02 06:18:19
172.19.0.129:80 80 236305
  • log_time - The current time when writing this log. The log action is called when the proxy session is closed.
  • worker_process_pid - the pid of worker process
  • client_ip - the client ip
  • host_ip - the server ip and port
  • accept_time - the time when the server accepts client's connection
  • upstream_ip - the upstream server's ip
  • bytes_read - the bytes read from client
  • bytes_write - the bytes written to client

allow

syntax: allow [ address | CIDR | all ]
default: none
context: server
description: Directive grants access for the network or addresses indicated.

deny

syntax: deny [ address | CIDR | all ]
default: none
context: server
description: Directive grants access for the network or addresses indicated.

so_keepalive

syntax: so_keepalive on|off
default: off
context: main, server
description: The same as so_keepalive (http://wiki.nginx.org/NginxMailCoreModule#so_keepalive).

tcp_nodelay

syntax: tcp_nodelay on|off
default: on
context: main, server
description: The same as tcp_nodelay (http://wiki.nginx.org/NginxHttpCoreModule#tcp_nodelay).

timeout

syntax: timeout milliseconds
default: 60000
context: main, server
description: set the timeout value with clients.

server_name

syntax: server_name name
default: The name of the host, obtained through gethostname()`
context: tcp, server
description: The same as server_name
(http://wiki.nginx.org/NginxMailCoreModule#server_name). You can specify several server name in different server block with the same port. They can be used in websocket module.

resolver

syntax: resolver address
default: none
context: tcp, server
description: DNS server

resolver_timeout

syntax: resolver_timeout time
default: 30s
context: tcp, server
description: Resolver timeout in seconds.

ngx_tcp_upstream_module

upstream

syntax: upstream {...}
default: none
context: tcp
description: All the upstream directives are contained in this block. The upstream server will be dispatched with round robin by default.

server

syntax: server name [parameters]
default: none
context: upstream
description: Most of the parameters are the same as server (http://wiki.nginx.org/NginxHttpUpstreamModule#server). Default port is 80.

check

syntax:

check interval=milliseconds [fall=count][rise=count]
[timeout=milliseconds] [type=tcp|ssl_hello|smtp|mysql|pop3|imap]

default: none, if parameters omitted, default parameters are interval=30000 fall=5 rise=2 timeout=1000
context: upstream
description: Add the health check for the upstream servers. At present,the check method is a simple tcp connect.
The parameters' meanings are:

  • interval: the check request's interval time.
  • fall(fall_count): After fall_count check failures, the server is marked down.
  • rise(rise_count): After rise_count check success, the server is marked up.
  • timeout: the check request's timeout.
  • type: the check protocol type:
    1.tcp is a simple tcp socket connect and peek one byte.
    2.ssl_hello sends a client ssl hello packet and receives the server ssl hello packet.
    3.http sends a http request packet, receives and parses the http response to diagnose if the upstream server is alive.
    4.smtp sends a smtp request packet, receives and parses the smtp response to diagnose if the upstream server is alive. The response begins with '2' should be an OK response.
    5.mysql connects to the mysql server, receives the greeting response to diagnose if the upstream server is alive.
    6.pop3 receives and parses the pop3 response to diagnose if the upstream server is alive. The response begins with '+' should bean OK response.
    7.imap connects to the imap server, receives the greeting response to diagnose if the upstream server is alive.

check_http_send

syntax: check_http_send http_packet
default: "GET / HTTP/1.0\r\n\r\n"
context: upstream
description: If you set the check type is http, then the check function will sends this http packet to check the upstream server.

check_http_expect_alive

syntax: check_http_expect_alive [ http_2xx | http_3xx | http_4xx | http_5xx ]
default: http_2xx | http_3xx
context: upstream
description: These status codes indicate the upstream server's http response is OK, the backend is alive.

check_smtp_send

syntax: check_smtp_send smtp_packet
default: "HELO smtp.localdomain\r\n"
context: upstream
description: If you set the check type is smtp, then the check function will sends this smtp packet to check the upstream server.

check_smtp_expect_alive

syntax: check_smtp_expect_alive [smtp_2xx | smtp_3xx | smtp_4xx | smtp_5xx]
default: smtp_2xx
context: upstream
description: These status codes indicate the upstream server's smtp response is OK, the backend is alive.

check_shm_size

syntax: check_shm_size size
default: (number_of_checked_upstream_blocks + 1) * pagesize
context: tcp
description: If you store hundreds of servers in one upstream block, the shared memory for health check may be not enough, you can enlarged it by this directive.

tcp_check_status

syntax: tcp_check_status
default: none
context: location
description: Display the health checking servers' status by HTTP. This directive is set in the http block.

The table field meanings are:

  • Index: The server index in the check table
  • Name : The upstream server name
  • Status: The marked status of the server.
  • Busyness: The number of connections which are connecting to the server.
  • Rise counts: Count the successful checking
  • Fall counts: Count the unsuccessful checking
  • Access counts: Count the times accessing to this server
  • Check type: The type of the check packet

ngx_tcp_upstream_busyness_module

busyness

syntax: busyness
default: none
context: upstream
description: the upstream server will be dispatched by backend servers busyness.

ngx_tcp_upstream_ip_hash_module

ip_hash

syntax: ip_hash
default: none
context: upstream
description: the upstream server will be dispatched by ip_hash.

ngx_tcp_proxy_module

proxy_pass

syntax: proxy_pass host:port
default: none
context: server
description: proxy the request to the backend server. Default port is 80.

proxy_buffer

syntax: proxy_buffer size
default: 4k
context: tcp, server
description: set the size of proxy buffer.

proxy_connect_timeout

syntax: proxy_connect_timeout miliseconds
default: 60000
context: tcp, server
description: set the timeout value of connection to backends.

proxy_read_timeout

syntax: proxy_read_timeout miliseconds
default: 60000
context: tcp, server
description: set the timeout value of reading from backends.

proxy_send_timeout

syntax: proxy_send_timeout miliseconds
default: 60000
context: tcp, server
description: set the timeout value of sending to backends.

ngx_tcp_websocket_module

websocket_pass

syntax: websocket_pass [path] host:port
default: none
context: server
description: proxy the websocket request to the backend server. Default port is 80. You can specify several different paths in the same server block.

websocket_buffer

syntax: websocket_buffer size
default: 4k
context: tcp, server
description: set the size of proxy buffer.

websocket_connect_timeout

syntax: websocket_connect_timeout miliseconds
default: 60000
context: tcp, server
description: set the timeout value of connection to backends.

websocket_read_timeout

syntax: websocket_read_timeout miliseconds
default: 60000
context: tcp, server
description: set the timeout value of reading from backends. Your timeout will be the minimum of this and the timeout parameter, so if you want a long timeout for your websockets, make sure to set both parameters.

websocket_send_timeout

syntax: websocket_send_timeout miliseconds
default: 60000
context: tcp, server
description: set the timeout value of sending to backends.

ngx_tcp_ssl_module

The default config file includes this ngx_tcp_ssl_module. If you want to just compile nginx without ngx_tcp_ssl_module, copy the ngx_tcp_proxy_module/config_without_ssl to ngx_tcp_proxy_module/config, reconfigrure and compile nginx.

ssl

syntax: ssl [on|off]
default: ssl off
context: tcp, server
Enables SSL for a server.

ssl_certificate

syntax: ssl_certificate file
default: ssl_certificate cert.pem
context: tcp, server
This directive specifies the file containing the certificate, in PEM format. This file can contain also other certificates and the server private key.

ssl_certificate_key

syntax: ssl_certificate_key file
default: ssl_certificate_key cert.pem
context: tcp, server
This directive specifies the file containing the private key, in PEM format.

ssl_client_certificate

syntax: ssl_client_certificate file
default: none
context: tcp, server
This directive specifies the file containing the CA (root) certificate, in PEM format, that is used for validating client certificates.

ssl_dhparam

syntax: ssl_dhparam file
default: none
context: tcp, server
This directive specifies a file containing Diffie-Hellman key agreement protocol cryptographic parameters, in PEM format, utilized for exchanging session keys between server and client.

ssl_ciphers

syntax: ssl_ciphers openssl_cipherlist_spec
default: ssl_ciphers HIGH:!aNULL:!MD5
context: tcp, server
This directive describes the list of cipher suites the server supports for establishing a secure connection. Cipher suites are specified in the OpenSSL (http://openssl.org/docs/apps/ciphers.html) cipherlist format,
for example:

ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;

The complete cipherlist supported by the currently installed version of OpenSSL in your platform can be obtained by issuing the command: openssl ciphers

ssl_crl

syntax: ssl_crl file
default: none
context: tcp, server
This directive specifies the filename of a Certificate Revocation List, in PEM format, which is used to check the revocation status of certificates.

ssl_prefer_server_ciphers

syntax: ssl_prefer_server_ciphers [on|off]
default: ssl_prefer_server_ciphers off
The server requires that the cipher suite list for protocols SSLv3 and TLSv1 are to be preferred over the client supported cipher suite list.

ssl_protocols

syntax: ssl_protocols [SSLv2] [SSLv3] [TLSv1] [TLSv1.1] [TLSv1.2]
default: ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2
context: tcp, server
This directive enables the protocol versions specified.

ssl_verify_client

syntax: ssl_verify_client on|off|optional
default: ssl_verify_client off
context: tcp, server
This directive enables the verification of the client identity.Parameter 'optional' checks the client identity using its certificate in case it was made available to the server.

ssl_verify_depth

syntax: ssl_verify_depth number
default: ssl_verify_depth 1
context: tcp, server
This directive sets how deep the server should go in the client provided certificate chain in order to verify the client identity.

ssl_session_cache

syntax: ssl_session_cache off|none|builtin:size and/or shared:name:size
default: ssl_session_cache off
context: tcp, server
The directive sets the types and sizes of caches to store the SSL sessions.
The cache types are:

  • off -- Hard off: nginx says explicitly to a client that sessions can not reused.
  • none -- Soft off: nginx says to a client that session can be reused,but nginx actually never reuses them. This is workaround for some mail clients as ssl_session_cache may be used in mail proxy as well as in HTTP server.
  • builtin -- the OpenSSL builtin cache, is used inside one worker process only. The cache size is assigned in the number of the sessions. Note: there appears to be a memory fragmentation issue using this method, please take that into consideration when using this. See "References" below.
  • shared -- the cache is shared between all worker processes. The sizeof the cache is assigned in bytes: 1 MB cache can contain roughly4000 sessions. Each shared cache must be given an arbitrary name. Ashared cache with a given name can be used in several virtual hosts.
    It's possible to use both types of cache — builtin and shared — simultaneously, for example:
ssl_session_cache builtin:1000 shared:SSL:10m;

Bear in mind however, that using only shared cache, i.e., without builtin, should be more effective.

ssl_session_timeout

syntax: ssl_session_timeout time
default: ssl_session_timeout 5m
context: tcp, server
This directive defines the maximum time during which the client can re-use the previously negotiated cryptographic parameters of the secure session that is stored in the SSL cache.

Compatibility

  • My test bed is 0.7.65+

Notes

The http_response_parse.rl and smtp_response_parse.rl are ragel (http://www.complang.org/ragel/) scripts , you can edit the script and compile it like this:

$ ragel -G2 http_response_parse.rl
$ ragel -G2 smtp_response_parse.rl

TODO

  • refact this module, make it more extendable for adding third-party modules
  • manipulate header like http module's proxy_set_header
  • built-in variable support
  • custom log format
  • syslog support
  • FTP/IRC proxying

Known Issues

  • This module can't use the same listening port with the HTTP module.

Changelogs

v0.2.0

  • add ssl proxy module
  • add websocket proxy module
  • add upstream busyness module
  • add tcp access log module

v0.19

  • add many check methods

v0.1

  • first release

Authors

Weibin Yao(姚伟斌) yaoweibin at gmail dot com

Copyright & License

This README template copy from agentzh (http://github.com/agentzh),I borrowed a lot of code from upstream and mail module from the nginx 0.7 core. This part of code is copyrighted by Igor Sysoev. And the health check part is borrowed the design of Jack Lindamood's healthcheck module healthcheck_nginx_upstreams (http://github.com/cep21/healthcheck_nginx_upstreams);
This module is licensed under the BSD license.

    Copyright (C) 2013 by Weibin Yao <[email protected]>.
    
    All rights reserved.
    
    Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are
    met:
    
    * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    
    * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the
        documentation and/or other materials provided with the distribution.
    
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
    IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
    TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
    PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
    TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

nginx_tcp_proxy_module's People

Contributors

chobits avatar dsugisawa-mixi avatar eliandrewc avatar jgable avatar jsoref avatar magicbear avatar nearapogee avatar notz avatar taomaree avatar tinywan avatar yaoweibin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nginx_tcp_proxy_module's Issues

check_http_send - issue with HOST HTTP header

Hi,

First of all thank you for great Nginx module!

During the healthcheck configuration I got an issue with the check_http_send directive. I need to specify the HOST header in my GET request, and as I know the HOST header should start from new line, but I am having troubles with it.

I tried the following configurations and all of them are not working. Please advice how to correctly add the HOST header to the GET request?

check_http_send "GET /health HTTP/1.0\r\n\r\n Host: example.com\r\n\r\n";

check_http_send "GET /health HTTP/1.0"
'Host: example.com';

Thanks in advance!
Eugene

include not working with tcp

Inside tcp block include is not working. It says:

Starting nginx: [emerg]: "include" directive is not allowed here in ...

Include is not working because NGX_ANY_CONF flags does not match NGX_TCP_MAIN_CONF etc.

Need to add this patch to tcp.patch

nginx-0.8.54/src/core/ngx_conf_file.c checks if flags match and jumps to not_allowed when they did not.

This patch allows to use include inside tcp block but I'm not really sure if this is right fix.

diff -ur nginx-0.8.54/src/core/ngx_conf_file.h nginx-0.8.54-/src/core/ngx_conf_file.h
--- nginx-0.8.54/src/core/ngx_conf_file.h       2010-02-12 11:45:05.000000000 +0200
+++ nginx-0.8.54-/src/core/ngx_conf_file.h      2011-03-30 16:46:51.000000000 +0300
@@ -49,7 +49,7 @@
 #define NGX_DIRECT_CONF      0x00010000

 #define NGX_MAIN_CONF        0x01000000
-#define NGX_ANY_CONF         0x0F000000
+#define NGX_ANY_CONF         0xFF000000

Can't find file to patch at input line 5

When I did as the document: patch -p1 < ./tcp.patch
I got the follow error:

can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
-------------------------------------------------
|diff --git a/src/core/ngx_log.c b/src/core/ngx_log.c
|index 770a590..26dd221 100644
|--- a/src/core/ngx_log.c
|+++ b/src/core/ngx_log.c
-------------------------------------------------
File to patch:

Then the shell seams to ask me to provide a file to patch.
What can i do ?

PS: My os is redhat 5

WebSocket with SSL is Instability

nginx.conf

tcp {
  upstream websockets {
    # node.js servers (e.g., socket.io servers)
    server xxx.xxx.xxx.xxx:3000;
    check interval=3000 rise=2 fall=5 timeout=1000;
  }

  server {
    server_name _;
    listen 443;
    ssl on;
    ssl_certificate      /path to crt;
    ssl_certificate_key  /path to key;
    so_keepalive on;
    tcp_nodelay on;
    proxy_pass websockets;
  }
}

When I do not use SSL, It's stable and work.
When 4-5 times access it, a server does not return a request.

stable without SSL

tcp {
  upstream websockets {
    # node.js servers (e.g., socket.io servers)
    server xxx.xxx.xxx.xxx:3000;
    check interval=3000 rise=2 fall=5 timeout=1000;
  }

  server {
    server_name _;
    listen 80;
    tcp_nodelay on;
    proxy_pass websockets;
  }
}

i used Nginx Version is 1.1.3 and nginx_tcp_proxy_module is develop branch(2012/01/24)

I think that it is SSL to be unstable, and it is not WebSocket.
In the static page, the same thing happens.

SSL support

It would be nice if the tcp proxy module could terminate ssl connections, like the http module can.

Websocket fails when buffer=0 (no way to turn off)

Noticing that the websocket proxy fails when the buffer is set to 0. There is also no way to turn it off, which is needed for this particular setup because there are small pings/pongs going in and out of the socket.

Compile error on arm

Hi,

I'm trying to compile the module with nginx 1.0.4 on an arm box and I get the following error:

gcc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Werror -g   -I src/core -I src/event -I src/event/modules -I src/os/unix -I modules/nginx_tcp_proxy_module//modules -I modules/nginx_tcp_proxy_module/ -I objs -I src/http -I src/http/modules -I src/mail \
                -o objs/addon/nginx_tcp_proxy_module/http_response_parse.o \
                modules/nginx_tcp_proxy_module//http_response_parse.c
cc1: warnings being treated as errors
http_response_parse.c: In function 'http_parser_execute':
http_response_parse.c:187: warning: comparison is always true due to limited range of data type
http_response_parse.c:209: warning: comparison is always true due to limited range of data type
make[1]: *** [objs/addon/nginx_tcp_proxy_module/http_response_parse.o] Error 1
make[1]: Leaving directory `/share/HDA_DATA/.qpkg/Optware/etc/nginx-1.0.4'
make: *** [build] Error 2

Any idea what the error is about?

Make error

After I do the ./configure --add-module=../yaoweibin-nginx_tcp_proxy_module-e312d8d/ --with-pcre=../pcre-8.11 --with-zlib=../zlib-1.2.5.1 --with-openssl=../openssl-1.0.0e and then make, I get the follow error at the end:

../yaoweibin-nginx_tcp_proxy_module-e312d8d//ngx_tcp_upstream.c: In function ‘ngx_tcp_upstream_connect’:
../yaoweibin-nginx_tcp_proxy_module-e312d8d//ngx_tcp_upstream.c:355: 错误:‘ngx_peer_connection_t’ 没有名为 ‘check_index’ 的成员
../yaoweibin-nginx_tcp_proxy_module-e312d8d//ngx_tcp_upstream.c:356: 错误:‘ngx_peer_connection_t’ 没有名为 ‘check_index’ 的成员
../yaoweibin-nginx_tcp_proxy_module-e312d8d//ngx_tcp_upstream.c: In function ‘ngx_tcp_upstream_finalize_session’:
../yaoweibin-nginx_tcp_proxy_module-e312d8d//ngx_tcp_upstream.c:551: 错误:‘ngx_peer_connection_t’ 没有名为 ‘check_index’ 的成员
../yaoweibin-nginx_tcp_proxy_module-e312d8d//ngx_tcp_upstream.c:552: 错误:‘ngx_peer_connection_t’ 没有名为 ‘check_index’ 的成员
../yaoweibin-nginx_tcp_proxy_module-e312d8d//ngx_tcp_upstream.c:553: 错误:‘ngx_peer_connection_t’ 没有名为 ‘check_index’ 的成员
make[1]: *** [objs/addon/yaoweibin-nginx_tcp_proxy_module-e312d8d/ngx_tcp_upstream.o] 错误 1
make[1]: Leaving directory `/root/tmp/nginx-1.1.0'
make: *** [build] 错误 2

Note: I did not do a patch like patch -p1 < tcp.patch for there is an error for the patch operation . see issue: #17

Problem building with latest from develop branch

seems to be a problem with the changes made a couple of days ago regarding SSL.
/Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c:27: error: ‘NGX_SSL_TLSv1_1’ undeclared here (not in a function)
/Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c:28: error: ‘NGX_SSL_TLSv1_2’ undeclared here (not in a function)

full build error:
/usr/bin/llvm-gcc -c -Os -w -pipe -march=core2 -msse4.1 -I src/core -I src/event -I src/event/modules -I src/os/unix -I /Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module/modules -I /Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module/parsers -I /Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module -I objs -I src/http -I src/http/modules -I src/mail
-o objs/addon/modules/ngx_tcp_ssl_module.o
/Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c
/Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c:27: error: ‘NGX_SSL_TLSv1_1’ undeclared here (not in a function)
/Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c:28: error: ‘NGX_SSL_TLSv1_2’ undeclared here (not in a function)
/Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c: In function ‘ngx_tcp_ssl_merge_srv_conf’:
/Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c:229: error: invalid operands to binary | (have ‘int’ and ‘struct ngx_conf_bitmask_t ’)
/Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c:229: error: invalid operands to binary | (have ‘struct ngx_conf_bitmask_t *’ and ‘struct ngx_conf_bitmask_t *’)
/Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c: In function ‘ngx_tcp_ssl_session_cache’:
/Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c:482: error: ‘ngx_ssl_session_cache_init’ undeclared (first use in this function)
/Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c:482: error: (Each undeclared identifier is reported only once
/Users/jreedy/development/apps/third-party/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c:482: error: for each function it appears in.)
make[1]: *
* [objs/addon/modules/ngx_tcp_ssl_module.o] Error 1

Make error in 9677e00fa2

In the latest commit to master, compilation fails:

/buildir/tcp/ngx_tcp_upstream.c: In function 'ngx_tcp_upstream_connect':
/buildir/tcp/ngx_tcp_upstream.c:355: error: 'ngx_peer_connection_t' has no member named 'check_index'
/buildir/tcp/ngx_tcp_upstream.c:356: error: 'ngx_peer_connection_t' has no member named 'check_index'
/buildir/tcp/ngx_tcp_upstream.c: In function 'ngx_tcp_upstream_finalize_session':
/buildir/tcp/ngx_tcp_upstream.c:551: error: 'ngx_peer_connection_t' has no member named 'check_index'
/buildir/tcp/ngx_tcp_upstream.c:552: error: 'ngx_peer_connection_t' has no member named 'check_index'
/buildir/tcp/ngx_tcp_upstream.c:553: error: 'ngx_peer_connection_t' has no member named 'check_index'
make[1]: *** [objs/addon/tcp/ngx_tcp_upstream.o] Error 1
make[1]: Leaving directory `/buildir/nginx'
make: *** [build] Error 

I also tried v0.24, but received a similar build error:

/buildir/tcp/ngx_tcp_core_module.c: In function 'ngx_tcp_core_resolver':
/buildir/tcp/ngx_tcp_core_module.c:471: warning: passing argument 2 of 'ngx_resolver_create' from incompatible pointer type
src/core/ngx_resolver.h:137: note: expected 'struct ngx_str_t *' but argument is of type 'struct ngx_addr_t *'
/buildir/tcp/ngx_tcp_core_module.c:471: error: too few arguments to function 'ngx_resolver_create'
make[1]: *** [objs/addon/tcp/ngx_tcp_core_module.o] Error 1
make[1]: Leaving directory `/buildir/nginx'
make: *** [build] Error 2

TCP SSL Session Resumption

I don't seem to get session resumption on TCP SSL sessions. When I add the directive "ssl_session_cache builtin:1000 shared:SSL:5m;", I get a segmentation fault when I test the configuration. The syntax of the file checks out ok. If I place the session cache directive under http, will it carry over for tcp connections? Can I even do session resumption under ssl?

Thanks...

Darren

Crash under 64bit

Unfortunately this module leads to worker crashes on a 64bit system.

How I came to this conclusion, I have 3 servers all running this module (2x32bit, 1x64bit) the single 64bit one had a worker crash rate of about 10 a second, it was getting crazy. after lots of debugging I recompiled without your module (and an altered config). and the crashes where gone.

I also tested with your module enabled, but without any TCP blocks and there where no crashes, after adding them back in the crashes restarted.

Running development branch, nginx 1.2.1

I dont know how to debug nginx workers, but if you give me the command I will do it.

crash at ngx_tcp_upstream_check.c:502

We had a crash and I debugged it. Seems that at ngx_tcp_check_clear_all_events nginx triest to destroy pool that does not exist actually.

            if (peer_conf[i].pool != NULL) {
502             ngx_destroy_pool(peer_conf[i].pool);
            }

Part of crash dump:

Core was generated by `nginx: worker process is shutting down'.
Program terminated with signal 11, Segmentation fault.
#0  ngx_destroy_pool (pool=0x1e9ae080) at src/core/ngx_palloc.c:51
51              if (c->handler) {
(gdb) where
#0  ngx_destroy_pool (pool=0x1e9ae080) at src/core/ngx_palloc.c:51
#1  0x00000000004c624c in ngx_tcp_check_clear_all_events () at ngx_tcp_proxy/ngx_tcp_upstream_check.c:502
#2  ngx_tcp_check_need_exit () at ngx_tcp_proxy/ngx_tcp_upstream_check.c:512
#3  0x00000000004c6aea in ngx_tcp_check_begin_handler (event=0x1e9ae080) at ngx_tcp_proxy/ngx_tcp_upstream_check.c:1532
#4  0x000000000042ac49 in ngx_event_expire_timers () at src/event/ngx_event_timer.c:149
...

And when I printed value out it seems that it is not proper, so I guess program tried to destroy something that was not pool.

(gdb) print *(*(ngx_tcp_check_peer_conf_t *) check_peers_ctx->peers.elts).pool
$15 = {d = {last = 0x0, end = 0xa0f81 <Address 0xa0f81 out of bounds>, next = 0x1, failed = 512119232}, max = 95, current = 0x1e8639a0, chain = 0x13, 

large = 0x1e86c248, cleanup = 0x85ba03e013e656fe, log = 0x1e86a9f8}

At ngx_tcp_check_init_process we create pool only if cf->need_pool is true and to force pool to be null we need following patch.

diff -ur a/ngx_tcp_upstream_check.c b/ngx_tcp_upstream_check.c
--- a/ngx_tcp_upstream_check.c 2011-03-29 15:53:22.000000000 +0300
+++ b/ngx_tcp_upstream_check.c        2011-03-29 15:53:04.000000000 +0300
@@ -1690,6 +1690,8 @@
             if (peer_conf[i].pool == NULL) {
                 return NGX_ERROR;
             }
+        } else {
+            peer_conf[i].pool = NULL;
         }

         peer_conf[i].send_handler = cf->send_handler;

How to install that on Ubuntu11

I have install nginx 1.2.1 on my server , and I wanna to add this module.

but like after I compiled the source I found that the new nginx is in /usr/local/nginx/sbin/nginx but not /usr/sbin/nginx
so I remove the old version and create a new one "ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx"

after that all my old conf files are disabled and the new conf file locate in /usr/local/nginx/conf
directive "tcp" can be recognized here, but all my old settings are disabled

so How can I install this module with the minimum operations...

make error

hi weibin,

Some errors has found, when I run make comand with the lastest nginx_tcp_proxy_module.

errors:

gcc -c -O -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I /data/software/nginx_tcp_proxy_module/modules -I /data/software/nginx_tcp_proxy_module/parsers -I /data/software/nginx_tcp_proxy_module -I /backup/software/pcre-7.7 -I /data/software/openssl-1.0.1c/openssl/include -I objs -I src/http -I src/http/modules -I src/mail
-o objs/addon/parsers/smtp_response_parser.o
/data/software/nginx_tcp_proxy_module/parsers/smtp_response_parser.c
gcc -c -O -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I /data/software/nginx_tcp_proxy_module/modules -I /data/software/nginx_tcp_proxy_module/parsers -I /data/software/nginx_tcp_proxy_module -I /backup/software/pcre-7.7 -I /data/software/openssl-1.0.1c/openssl/include -I objs -I src/http -I src/http/modules -I src/mail
-o objs/addon/modules/ngx_tcp_ssl_module.o
/data/software/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c
cc1: warnings being treated as errors
/data/software/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c: In function ‘ngx_tcp_ssl_merge_srv_conf’:
/data/software/nginx_tcp_proxy_module/modules/ngx_tcp_ssl_module.c:336: warning: implicit declaration of function ‘ngx_ssl_crl’
make[1]: *** [objs/addon/modules/ngx_tcp_ssl_module.o] Error 1
make[1]: Leaving directory `/data/software/nginx-0.7.61'

make: *** [build] Error 2

Here is configure arguments: --prefix=/usr/local/nginx --with-http_stub_status_module --with-pcre=/backup/software/pcre-7.7 --without-http-cache --add-module=/backup/software/sessionstick --with-http_ssl_module --with-openssl=/data/software/openssl-1.0.1c --add-module=/data/software/nginx_tcp_proxy_module

nginx version is 0.7.61.

nginx 1.2.1 works ok.

server_name ignored

Hey guys,

Is it possible that the server_name directive in the server directive is be ignored?

If I write something like:

tcp {
upstream cluster {
server 127.0.0.1:8000;

    check interval=3000 rise=2 fall=5 timeout=1000;
}   

server {
    listen 9000;
    server_name test.example.com;

    tcp_nodelay on;
    proxy_pass cluster;
}

}

The server is reachable by test.example.com:9000, test2.example.com:9000 and all other subdomains and the main domain.

Error on build

gcc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Werror -g   -I src/core -I src/event -I src/event/modules -I src/os/unix -I ../nginx_tcp_proxy_module/modules -I ../nginx_tcp_proxy_module -I objs -I src/http -I src/http/modules -I src/mail \
    -o objs/addon/nginx_tcp_proxy_module/ngx_tcp_upstream.o \
    ../nginx_tcp_proxy_module/ngx_tcp_upstream.c
../nginx_tcp_proxy_module/ngx_tcp_upstream.c: In function ‘ngx_tcp_upstream_next’:
../nginx_tcp_proxy_module/ngx_tcp_upstream.c:464:17: error: variable ‘state’ set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors

make[1]: *** [objs/addon/nginx_tcp_proxy_module/ngx_tcp_upstream.o] Error 1
make[1]: Leaving directory `/home/pierre/builds/nginx-1.0.4'
make: *** [build] Error 2

xmpp

I haven't test for now, but will you module work with xmpp connections ?
(And if not, that can be a VERY good idea :))

Error on build

I'm getting the following error on build in 0.8.54 (also just tried with 0.8.53). Any ideas?

            -o objs/addon/yaoweibin-nginx_tcp_proxy_module-0d564d6/ngx_tcp_upstream.o \
            /usr/local/src/nginx_tcp_proxy_module/yaoweibin-nginx_tcp_proxy_module-0d564d6/ngx_tcp_upstream.c

make[1]: Leaving directory `/tmp/vagrant-chef/nginx-0.8.54'STDERR: /usr/local/src/nginx_tcp_proxy_module/yaoweibin-nginx_tcp_proxy_module-0d564d6/ngx_tcp_upstream.c: In function 'ngx_tcp_upstream_connect':
/usr/local/src/nginx_tcp_proxy_module/yaoweibin-nginx_tcp_proxy_module-0d564d6/ngx_tcp_upstream.c:355: error: 'ngx_peer_connection_t' has no member named 'check_index'
/usr/local/src/nginx_tcp_proxy_module/yaoweibin-nginx_tcp_proxy_module-0d564d6/ngx_tcp_upstream.c:356: error: 'ngx_peer_connection_t' has no member named 'check_index'
/usr/local/src/nginx_tcp_proxy_module/yaoweibin-nginx_tcp_proxy_module-0d564d6/ngx_tcp_upstream.c: In function 'ngx_tcp_upstream_finalize_session':
/usr/local/src/nginx_tcp_proxy_module/yaoweibin-nginx_tcp_proxy_module-0d564d6/ngx_tcp_upstream.c:551: error: 'ngx_peer_connection_t' has no member named 'check_index'
/usr/local/src/nginx_tcp_proxy_module/yaoweibin-nginx_tcp_proxy_module-0d564d6/ngx_tcp_upstream.c:552: error: 'ngx_peer_connection_t' has no member named 'check_index'
/usr/local/src/nginx_tcp_proxy_module/yaoweibin-nginx_tcp_proxy_module-0d564d6/ngx_tcp_upstream.c:553: error: 'ngx_peer_connection_t' has no member named 'check_index'
make[1]: *** [objs/addon/yaoweibin-nginx_tcp_proxy_module-0d564d6/ngx_tcp_upstream.o] Error 1

mutliple upstream-servers for different locations

I'd like to be able to host several node-instances (e.g. foo at port 8000 and bar at port 9000) and proxy them into a 'location {}' as if they'd be a normal 'upstream {}':

#improper example ;-)

upstream foo { tcp { [...] server localhost:8000; } }
upstream bar { tcp { [...] server localhost:9000; } }
location /foo { index @foo; }
location /bar { index @bar; }

As far as i understood the readme this is not possible at the moment.

timeouts

It is not an app issue.

I'm preparing to use this module as a websocket proxy and it works fine. The only thing is that the conection is not kept alive, but it is reset every minute.
I found out there are some configuration timeouts, wich I suppose I have to give a huge value to minimize the restarts.

Anyway the "issue" would be that in the documentation here in github says timeouts are in miliseconds and, in my case I found out it works in secconds.

build failing on Ubuntu 12.04

Hello,
I upgraded the server yesterday from Oneiric, kept the deb package I created earlier with the tcp proxy patch and it's working, however when I tried to recompile it for the current arch I get this:

/home/ubuntu/source/nginx-1.2.1/../nginx_tcp_proxy_module/ngx_tcp_session.c: In function ‘ngx_tcp_send’:
/home/ubuntu/source/nginx-1.2.1/../nginx_tcp_proxy_module/ngx_tcp_session.c:351:5: error: ‘NGX_LOG_DEBUG_TCP’ undeclared (first use in this function)
/home/ubuntu/source/nginx-1.2.1/../nginx_tcp_proxy_module/ngx_tcp_session.c:351:5: note: each undeclared identifier is reported only once for each function it appears in
/home/ubuntu/source/nginx-1.2.1/../nginx_tcp_proxy_module/ngx_tcp_session.c: In function ‘ngx_tcp_finalize_session’:
/home/ubuntu/source/nginx-1.2.1/../nginx_tcp_proxy_module/ngx_tcp_session.c:410:5: error: ‘NGX_LOG_DEBUG_TCP’ undeclared (first use in this function)
/home/ubuntu/source/nginx-1.2.1/../nginx_tcp_proxy_module/ngx_tcp_session.c: In function ‘ngx_tcp_close_connection’:
/home/ubuntu/source/nginx-1.2.1/../nginx_tcp_proxy_module/ngx_tcp_session.c:431:5: error: ‘NGX_LOG_DEBUG_TCP’ undeclared (first use in this function)
/home/ubuntu/source/nginx-1.2.1/../nginx_tcp_proxy_module/ngx_tcp_session.c: In function ‘ngx_tcp_cleanup_add’:
/home/ubuntu/source/nginx-1.2.1/../nginx_tcp_proxy_module/ngx_tcp_session.c:519:5: error: ‘NGX_LOG_DEBUG_TCP’ undeclared (first use in this function)
make[2]: *** [objs/addon/nginx_tcp_proxy_module/ngx_tcp_session.o] Error 1
make[2]: Leaving directory `/home/ubuntu/source/nginx-1.2.1/debian/build-full'
make[1]: *** [build] Error 2
make[1]: Leaving directory `/home/ubuntu/source/nginx-1.2.1/debian/build-full'
make: *** [build-arch.full] Error 2
dpkg-buildpackage: error: debian/rules build gave error exit status 2

Full steps:

sudo -s
nginx=stable # use nginx=development for latest development version
add-apt-repository ppa:nginx/$nginx
apt-get update
git clone https://github.com/yaoweibin/nginx_tcp_proxy_module.git ~/source/nginx_tcp_proxy_module
cd nginx_tcp_proxy_module
git checkout --track -b develop origin/develop # check if you want develop branch or master and act accordingly
cd ~/source
apt-get source nginx
sudo apt-get install libexpat-dev libgd2-noxpm-dev libgeoip-dev liblua5.1-dev libmhash-dev libpcre3-dev libperl-dev po-debconf debhelper
cd nginx-1.2.1
nano debian/rules # modify the "full" config and add
--add-module=$(CURDIR)/../nginx_tcp_proxy_module \
sudo dpkg-buildpackage -us -uc
cd ..
sudo dpkg -i nginx-full_1.2.1-0ubuntu0ppa1~oneiric_i386.deb # install the resulting package

RC for develop branch?

I wonder how the develop branch is? I'm now getting a tarball at 4a048df and was wondering if there might be a release candidate any time soon? I don't mind getting at a SHA, but it would be nice were there something that is presumed to have a bit of stability.

mysql max connections errors

I have the proxy working now, but I have a new issue. I created a simple test proxy to an internal mysql server I have. It worked fine for the first couple of connections, then I received this error:

'hostname' is blocked because of many connection errors. Unblock with 'mysqladmin flush-hosts'

By default mysql is set to 10 max connection errors. In order to compensate, I increased the max_connection_errors variable in mysql to 5000. I really didn't want to make many changes on the MySQL side. Below is what I have in nginx:

check interval=3000 rise=2 fall=5 timeout=1000 type=mysql;

This is the default with the type of mysql added. I would like to know how I can fix this in nginx vs making changes in mysql configuration. If it can't be fixed in nginx, then I will just stick to the changes in mysql for now. Thanks!

多server的解析问题

tcp {

    upstream cluster1 {
        server 192.168.1.38:3306;
    }

    upstream cluster2 {
        server 192.168.1.196:3306;
    }
    server {
        listen 8888;
        server_name dd.com;
        proxy_pass cluster1;
    }
    server {
        listen 8888;
        server_name d1.com;
        proxy_pass cluster2;
    }
}

当我链接d1.com的8888端口的时候,链接到的还是dd.com的8888端口,如何解决

Nginx 1.0

Hi, thanks for great module, I'm from the websocket bunch. There seems to be a problem while compiling with nginx 1.x


gcc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Werror -g   -I src/core -I src/event -I src/event/modules -I src/os/unix -I ../nginx_tcp_proxy_module/modules -I ../nginx_tcp_proxy_module -I /opt/local/include -I objs -I src/http -I src/http/modules -I src/mail \
                -o objs/addon/nginx_tcp_proxy_module/ngx_tcp_upstream.o \
                ../nginx_tcp_proxy_module/ngx_tcp_upstream.c
../nginx_tcp_proxy_module/ngx_tcp_upstream.c: In function ‘ngx_tcp_upstream_connect’:
../nginx_tcp_proxy_module/ngx_tcp_upstream.c:355: error: ‘ngx_peer_connection_t’ has no member named ‘check_index’
../nginx_tcp_proxy_module/ngx_tcp_upstream.c:356: error: ‘ngx_peer_connection_t’ has no member named ‘check_index’
../nginx_tcp_proxy_module/ngx_tcp_upstream.c: In function ‘ngx_tcp_upstream_finalize_session’:
../nginx_tcp_proxy_module/ngx_tcp_upstream.c:551: error: ‘ngx_peer_connection_t’ has no member named ‘check_index’
../nginx_tcp_proxy_module/ngx_tcp_upstream.c:552: error: ‘ngx_peer_connection_t’ has no member named ‘check_index’
../nginx_tcp_proxy_module/ngx_tcp_upstream.c:553: error: ‘ngx_peer_connection_t’ has no member named ‘check_index’
make[1]: *** [objs/addon/nginx_tcp_proxy_module/ngx_tcp_upstream.o] Error 1
make: *** [build] Error 2

"tcp" directive is not allowed here

Hi there,

I have a websocket application that runs on a port on the local machine - I've recompiled nginx 1.2.3 with the TCP module, and have created a file for sites-enabled/dashboard.conf.

The file is as follows:

tcp {
    upstream websockets {
        server 127.0.0.1:35005;
        server 127.0.0.1:35005;

        check interval=3000 rise=2 fall=5 timeout=1000;
    }

    server {
        listen  1270.0.01:80;
        server_name     dashboard.foo.com;
        access_log      /var/log/nginx/foo.dashboard.access.log;

        tcp_nodelay on;
        proxy_pass websockets
    }
}

However I get an error:

Restarting nginx: nginx: [emerg] "tcp" directive is not allowed here in /etc/nginx/sites-enabled/dashboard.conf:1

This server runs multiple subdomains for this application, with the dashboard subdomain being the only one currently needing websockets.

Any ideas how I can get this working?

Make Error

Hello,

I seem to be having a problem with compiling the latest version of nginx with your module.

-o objs/addon/nginx_tcp_proxy_module/ngx_tcp.o
/opt/nginx_tcp_proxy_module/ngx_tcp.c
gcc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I /opt/nginx_tcp_proxy_module/modules -I /opt/nginx_tcp_proxy_module -I objs -I src/http -I src/http/modules -I src/mail
-o objs/addon/nginx_tcp_proxy_module/ngx_tcp_core_module.o
/opt/nginx_tcp_proxy_module/ngx_tcp_core_module.c
/opt/nginx_tcp_proxy_module/ngx_tcp_core_module.c: In function ‘ngx_tcp_core_resolver’:
/opt/nginx_tcp_proxy_module/ngx_tcp_core_module.c:471:5: error: passing argument 2 of ‘ngx_resolver_create’ from incompatible pointer type [-Werror]
src/core/ngx_resolver.h:136:17: note: expected ‘struct ngx_str_t *’ but argument is of type ‘struct ngx_addr_t *’
/opt/nginx_tcp_proxy_module/ngx_tcp_core_module.c:471:5: error: too few arguments to function ‘ngx_resolver_create’
src/core/ngx_resolver.h:136:17: note: declared here
cc1: all warnings being treated as errors

make[1]: *** [objs/addon/nginx_tcp_proxy_module/ngx_tcp_core_module.o] Error 1
make[1]: Leaving directory `/root/nginx-1.1.11'
make: *** [build] Error 2

OS: Ubuntu 11.10 64-bit
Nginx Version: 1.1.11
Patch Applied: Yes

TCP SSL Support

I don't know why when I making nginx with tcp module (websocket branch) it will raise the follow exceptions:

gcc -c -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Werror -g -I src/core -I src/event -I src/event/modules -I src/os/unix -I ../ngx_tcp_proxy//modules -I ../ngx_tcp_proxy/ -I /opt/local/include -I objs -I src/http -I src/http/modules -I src/mail
-o objs/addon/ngx_tcp_proxy/ngx_tcp.o
../ngx_tcp_proxy//ngx_tcp.c
In file included from ../ngx_tcp_proxy/ngx_tcp.h:32,
from ../ngx_tcp_proxy//ngx_tcp.c:5:
../ngx_tcp_proxy/ngx_tcp_upstream_round_robin.h:30: error: expected specifier-qualifier-list before ‘ngx_ssl_session_t’
In file included from ../ngx_tcp_proxy/ngx_tcp.h:35,
from ../ngx_tcp_proxy//ngx_tcp.c:5:
../ngx_tcp_proxy//modules/ngx_tcp_ssl_module.h:14: error: expected specifier-qualifier-list before ‘ngx_ssl_t’
make[1]: *** [objs/addon/ngx_tcp_proxy/ngx_tcp.o] Error 1
make: *** [build] Error 2

and then I commented out all ssl configures in config file, the problem is solved.

nginx version 0.8.53~1.1.5, OSX 10.7.2

error: ‘NGX_INVALID_CHECK_INDEX’ undeclared

I got an error when running make on master branch. I am compiling nginx-0.8.53

./configure --with-http_ssl_module  --add-module=../nginx_tcp_proxy_module/ --prefix=/opt/local/nginx
gcc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Werror -g   -I src/core -I src/event -I src/event/modules -I src/os/unix -I ../nginx_tcp_proxy_module//modules -I ../nginx_tcp_proxy_module//parsers -I ../nginx_tcp_proxy_module/ -I /opt/local/include -I objs -I src/http -I src/http/modules -I src/mail \
        -o objs/addon/nginx_tcp_proxy_module/ngx_tcp_upstream.o \
        ../nginx_tcp_proxy_module//ngx_tcp_upstream.c
../nginx_tcp_proxy_module//ngx_tcp_upstream.c: In function ‘ngx_tcp_upstream_connect’:
../nginx_tcp_proxy_module//ngx_tcp_upstream.c:357: error: ‘NGX_INVALID_CHECK_INDEX’ undeclared (first use in this function)
../nginx_tcp_proxy_module//ngx_tcp_upstream.c:357: error: (Each undeclared identifier is reported only once
../nginx_tcp_proxy_module//ngx_tcp_upstream.c:357: error: for each function it appears in.)
../nginx_tcp_proxy_module//ngx_tcp_upstream.c: In function ‘ngx_tcp_upstream_next’:
../nginx_tcp_proxy_module//ngx_tcp_upstream.c:503: error: ‘NGX_INVALID_CHECK_INDEX’ undeclared (first use in this function)
../nginx_tcp_proxy_module//ngx_tcp_upstream.c: In function ‘ngx_tcp_upstream_finalize_session’:
../nginx_tcp_proxy_module//ngx_tcp_upstream.c:559: error: ‘NGX_INVALID_CHECK_INDEX’ undeclared (first use in this function)
make[1]: *** [objs/addon/nginx_tcp_proxy_module/ngx_tcp_upstream.o] Error 1
make: *** [build] Error 2

Thank you for any help!

HOWTO for websckets

Hey

Not really an issue, but more of a request. Would this module fit the needs of loadbalancing with a wbesocket backend? If so, how?

Websocket closing after a minute of being idle

First off thanks for this module! Been searching everywhere to get websockets to work through a proxy. I'm having an issue though that I am not seeing in development. When in production (and behind nginx), the socket is closing after a minute of being idle. Is this expected behavior? Do I need to do anything to keep it alive?

Thanks!

Shared log file

If I have an access log in the http section, can I use the same log file in the tcp section (I take responsibility for formatting the rows the same, its a basic log with only IPs)?

ngx_tcp_session.c:218:31: error: variable ‘s’ set but not used

I attempted to compile the develop branch at 58217c6. I got an error when running make. I am compiling nginx 1.20. I an not quire sure how to fix this.

sudo ./configure --with-http_ssl_module --add-module=/usr/local/src/nginx_tcp_proxy_module

Error when running make:

        -o objs/addon/nginx_tcp_proxy_module/ngx_tcp_session.o \
        /usr/local/src/nginx_tcp_proxy_module/ngx_tcp_session.c
/usr/local/src/nginx_tcp_proxy_module/ngx_tcp_session.c: In function ‘ngx_tcp_ssl_handshake_handler’:
/usr/local/src/nginx_tcp_proxy_module/ngx_tcp_session.c:218:31: error: variable ‘s’ set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors
make[1]: *** [objs/addon/nginx_tcp_proxy_module/ngx_tcp_session.o] Error 1
make[1]: Leaving directory `/usr/local/src/nginx-1.2.0'
make: *** [build] Error 2

reload log file (logrotate)

When the nginx daemon is reloaded, the logfile handle isnt updated.

It is common for logrotate to change move the file and then reload nginx to reload the handle to log to a new file.

unknown directive "proxy_set_header"

I operate Nginx as reverse proxy and, for the server of the backend, want to transfer header information.

proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

However, an error occurs as follows.

nginx: [emerg] unknown directive "proxy_set_header" in /usr/local/nginx/conf/nginx.conf:XXX

The contents which I set are as follows.

server {
  server_name _;

  listen 443;
  ssl on;
  ssl_certificate      /crtpath;
  ssl_certificate_key  /keypath;

  tcp_nodelay on;
  proxy_pass websockets;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header Host $host;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Is not the transfer of the header possible?

unknown directive "tcp"

Nginx version: 1.0.13

I am building an rpm version of nginx using the latest stable version. I have a patch directive in my spec file pointing to the tcp.patch file and I get no errors when it builds. Once it builds and I install the RPM, I get the "unknown directive" error. It shows the correct build options and lists the module in nginx -V. Nginx does not seem to have a problem and starts and runs fine until I create a config file that has the tcp option in it. I build this on RHEL 6. Is there an issue with 1.0.13 or is there a particular version that this module works with only. Thanks!

TLSv1.2 ?

Hi - Is there any issue with newer versions of TLS? E.g.,

# /etc/init.d/nginx start
Starting nginx: nginx: [warn] invalid value "TLSv1.2" in /etc/nginx/sites-available/app.com.conf:69

Compile error with nginx-1.1.5 and nginx-gridfs

I can build the nginx_tcp_proxy module without any problem. As soon as i add the the gridfs module to the build process i get errors during the nginx_tcp_proxy build.

cc1: warnings being treated as errors
In file included from ../nginx_tcp_proxy_module/ngx_tcp.h:30,
                 from ../nginx_tcp_proxy_module//ngx_tcp.c:5:
../nginx_tcp_proxy_module/ngx_tcp_upstream.h:120: error: declaration does not declare anything
make[1]: *** [objs/addon/nginx_tcp_proxy_module/ngx_tcp.o] Error 1
make[1]: Leaving directory `/opt/build/nginx-1.1.5'
make: *** [build] Error 2
make -f objs/Makefile install
make[1]: Entering directory `/opt/build/nginx-1.1.5'
gcc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value -Werror -g  --std=c99 -Isrc  -I src/core -I src/event -I src/event/modules -I src/os/unix -I ../nginx_tcp_proxy_module//modules -I ../nginx_tcp_proxy_module/ -I objs -I src/http -I src/http/modules -I src/mail \
        -o objs/addon/nginx_tcp_proxy_module/ngx_tcp.o \
        ../nginx_tcp_proxy_module//ngx_tcp.c
cc1: warnings being treated as errors
In file included from ../nginx_tcp_proxy_module/ngx_tcp.h:30,
                 from ../nginx_tcp_proxy_module//ngx_tcp.c:5:
../nginx_tcp_proxy_module/ngx_tcp_upstream.h:120: error: declaration does not declare anything

When i remove the -Werror from the nginx Makfile, the build fails on bit later:

gcc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Wunused-function -Wunused-variable -Wunused-value  -g  --std=c99 -Isrc  -I src/core -I src/event -I src/event/modules -I src/os/unix -I ../nginx_tcp_proxy_module//modules -I ../nginx_tcp_proxy_module/ -I objs -I src/http -I src/http/modules -I src/mail \
        -o objs/addon/nginx_tcp_proxy_module/ngx_tcp_upstream.o \
        ../nginx_tcp_proxy_module//ngx_tcp_upstream.c
In file included from ../nginx_tcp_proxy_module/ngx_tcp.h:30,
                 from ../nginx_tcp_proxy_module//ngx_tcp_upstream.c:4:
../nginx_tcp_proxy_module/ngx_tcp_upstream.h:120: warning: declaration does not declare anything
../nginx_tcp_proxy_module//ngx_tcp_upstream.c:82: error: ‘ngx_tcp_upstream_srv_conf_t’ has no member named ‘status_alive’
../nginx_tcp_proxy_module//ngx_tcp_upstream.c:89: error: ‘ngx_tcp_upstream_srv_conf_t’ has no member named ‘status_alive’
../nginx_tcp_proxy_module//ngx_tcp_upstream.c: In function ‘ngx_tcp_upstream_add’:
../nginx_tcp_proxy_module//ngx_tcp_upstream.c:656: error: ‘ngx_tcp_upstream_srv_conf_t’ has no member named ‘status_alive’
../nginx_tcp_proxy_module//ngx_tcp_upstream.c:656: warning: statement with no effect

Iam sure that this build failure only shows up when i add the gridfs module to the build.

Update Readme

Update the nginx wget in the readme, its very old. I presume it works with latest?

check_status

Hello! I have a few questions.

  1. Please tell us the meaning of the fields in the table that the output of the check_status.
  2. I have this problem. There is a server written in Python / Twisted uses to connect to the web sockets. On it were sufficiently high loads, and I decided to make a cluster. Advantage of your leadership and everything turned out. Queries in round robin went on all 6 servers, but there was such probelma - after connecting to the server after a while the connection is lost and re-appears. You do not know what it can be connected?

Thank you.

uname-a
Linux 2.6.32-30-server # 59-Ubuntu SMP Tue Mar 1 22:46:09 UTC 2011 x86_64 GNU / Linux

config:

tcp {
upstream backend {
server 95.169.184.31:8044;
server 95.169.184.31:8045;
server 95.169.184.31:8046;
server 95.169.184.31:8047;
server 95.169.184.31:8048;
server 95.169.184.31:8049;
check interval = 3000 rise = 2 fall = 5 timeout = 10000;
}

server {
listen *: 8043;
tcp_nodelay on;
proxy_pass backend;
}
}

http {

     server {
             listen 9000;
             location / wstat {
                     check_status;
             }
     }

}

basic auth htpsswd

Hi, if you could implement the basic auth with htpasswd it would be very nice and the module complete, in my opinion.
Thank you very much

1

1

explicitly handle specific path

Hi,
I'm new to nginx, so my question may seems silly. Anyway, I'm trying to come up with configuration of nginx which will allow proxy to websocket server only for specific path, e.g. /websocket, while preserve all other paths (including default one /) intact and handled by http nginx configuration. How can I do that? I found that I can explicitly add new location in http section, but default one is still redirected to tcp proxy. In other words, right now the the proxy redirection is done implicitly, while I'd like to have explicit redirection.
Thanks,
Valentin.

support for proxy_set_header

It would be nice if proxy_set_header can be supported in the configuration. I need to pass the real IP of the websocket connection to my proxy. I tried adding it but config test failed after adding it. I guess it's not supported.

host not found in upstream "chat1"

Hi!
Could you help me?

I have got error message nginx: [emerg] host not found in upstream "chat1" in /etc/nginx/sites-enabled/chat.bartermill.com:23

I have put into nginx.conf at the and of file below http {}

tcp {
upstream chat1 {
server 127.0.0.1:8001;
check interval=3000 rise=2 fall=5 timeout=1000;
}
}

and put into chat.bartermill.com (virtual server)

server {
listen chat.bartermill.com:80;
error_log /var/www/logs/chat-nginx-error.log warn;
location /websocket_status {
check_status;
}

location / {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://chat1;
            }
    }

Version nginx-1.0.14

Regards,
Rostyslav

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.