I built a NGINX reverse proxy where I listen for UDP traffic on port 53 and pass it on to an HTTP endpoint with modified headers. Once the headers are modified, I send the packet to the target.


http {  
include       /etc/nginx/mime.types;    
default_type  application/octet-stream;

log_format  main  '$remote_addr:$server_port - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';      

access_log  /var/log/nginx/access.log  main;
error_log /var/log/nginx/error.log debug;    

proxy_pass_request_headers on;    

sendfile        on;
#tcp_nopush     on;

keepalive_timeout  120;  
#gzip  on;     

server {
    listen 8080;       
        ngx.req.set_header("Host", "some_host")
        ngx.req.set_header("Content-Type", "application/atom+xml;type=entry;charset=utf-8") 
        ngx.req.set_header("Authorization", "some_token")
    location = / {                        
        proxy_pass https://the_real_target;                                                     


    stream {
    upstream some_name {

    server {
        listen      80;      
        proxy_pass  some_name;         

    server {
        listen 53 udp;
        proxy_responses 0; 
        proxy_pass some_name;


user  nginx;
load_module modules/ndk_http_module.so;
load_module modules/ngx_http_lua_module.so;
load_module modules/ngx_http_headers_more_filter_module.so;

include conf.d/stream.conf;
include conf.d/http.conf;

worker_processes  auto;

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

events {
    worker_connections  1024;

It works when I use Postman and send requests to port 80. However, when use PacketSender to send request over UDP it is not redirecting to the HTTP server and closes the connection.

I developed a program to test if I can redirect a UDP packet to a TCP endpoint. This works but I am looking for a way to accomplish this only with NGINX. Any ideas?

  • I doubt that nginx would do protocol conversions when proxying. The process is quite complex since the protocols are so different. What is the actual problem you are trying to solve? – Tero Kilkanen Apr 5 at 21:42
  • I am trying to solve the problem of receiving TCP packets with signal data and redirect the data to an HTTP target for further processing. – Brundlfly Apr 14 at 16:10
  • Is it TCP or UDP? Anyway, since nginx is an HTTP server, and HTTP is specified only to use TCP as a transport, it is the only thing that nginx supports. What is the protocol standard your devices are using to send the signal data over UDP? – Tero Kilkanen Apr 14 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.