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.conf
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;
access_by_lua_block
{
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.conf
stream {
upstream some_name {
server 127.0.0.1:8080;
}
server {
listen 80;
proxy_pass some_name;
}
server {
listen 53 udp;
proxy_responses 0;
proxy_pass some_name;
}
}
nginx.conf
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?