0

I am using NGINX as a reverse proxy for TCP streams. The server listens to 6680 TCP ports (not a typo) and pushes them on to upstream server(s) on port 5000. In the filter phase there is a njs script involved that injects the original destination port to the payload of the packet so that my application knows it.

It appears that when I uncomment the line that enables the njs script to run,

js_filter injectPort;

the NGINX memory usage steadily increases to the point that the system is exhausted.

My NGINX configuration:

user  nginx;
worker_processes auto;
worker_rlimit_nofile 65535;

error_log  /var/log/nginx/error.log info;
pid        /var/run/nginx.pid;

load_module modules/ngx_stream_js_module.so;

events {
    worker_connections  65535;
}

stream {
        js_include inject_filter.js;
        server {
                include listen_tcp.conf;
                js_filter injectPort;
                proxy_pass backends ;
        }

        upstream backends {
                server 0.0.0.0:5000;
        }
}

inject_filter.js script

function injectPort(s){
    s.on('upload', function(data,flags){
        s.send(s.variables.server_port + data, flags);
        return;
    });
}

I have tried directly inserting the content of: include listen_tcp.conf; inside the nginx.conf with no changes. Also I substituted my application with a dummy TCP listening server nc -l -k -vv -w 30 -m 999999 5000 without luck as well.

Any help is appreciated.

Feel free to suggest (production ready) alternatives for injecting the port in the packet's payload. Can iptables do this?

  • Is it possible that you are missing a "s.off('upload');" after the s.send ? Just taking a guess here as I saw that in another example. Let me know if you've made anymore progress with this as I'm trying to do something similar. – Bob Apr 02 '19 at 20:11
  • @Bob thanks for your input. If you add the s.off you will miss all the upload events on all the subsequent upload events for the stream at hand. – mantzouric Apr 04 '19 at 13:08

0 Answers0