Search code examples
nginxproxystreamreverse

nginx server_name inside stream block possible?


Current setup as follows:

stream {
    server {
        listen 9987 udp;

        server_name  subdomain.EXAMPLE.com; # this line is resulting in an error

        proxy_pass localhost:9987;
        proxy_timeout 1s;
        proxy_responses 1;
        error_log logs/dns.log;
    }
}

server_name subdomain.EXAMPLE.com;

Is this possible?

$nginx -t

$nginx: [emerg] "server_name" directive is not allowed here in /etc/nginx/nginx.conf:15

Works just fine without server_name, but I'd like to use a sub-domain if possible. (I am using a build with --with-stream, thats not my issue.)


Solution

  • TCP has no concept of server names, so this is not possible. It only works in HTTP because the client sends the hostname it is trying to access as part of the request, allowing nginx to match it to a specific server block.

    Source: https://forum.nginx.org/read.php?2,263208,263217#msg-263217