Udp Forwarding with Nginx

UDP forwarding with nginx

So this did seem to be the solution (in my note above).

If using my example from above, you want this to look like:

 stream {
server {
listen 11016 udp;
proxy_pass juniper_close_stream_backend;
proxy_responses 0;
}
}

This tells nginx not to expect a response, which it shouldn't need from UDP. I don't know why their examples don't show this when discussing DNS, which can be entirely UDP driven.

Differentiate between source address of udp packets

Managed to solve it by using a map. Updated config is now

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
worker_connections 1024;
}

stream {
#define the various upstreams
upstream app_1 {
server 127.0.0.1:5678;
}

upstream app_2 {
server 127.0.0.1:9000;
}
#map source port to upstream
map $remote_port $backend_svr {
1234 "app_1";
1235 "app_2";
}
#all udp traffic received on 8000, depending on source it will be redirected
server {
listen 8000 udp;
proxy_pass $backend_svr;
}

}

Is it possible to forward NON-http connecting request to some other port in nginx?

It is possible since nginx 1.9.0:

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

Something along these lines (this goes on top level of nginx.conf):

stream {
upstream backend {
server backend1.example.com:12345;
}

server {
listen 12345;
proxy_pass backend;
}
}


Related Topics



Leave a reply



Submit