nginx server_name inside stream block possible?

12,611

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

Share:
12,611
Emmmm
Author by

Emmmm

Updated on June 05, 2022

Comments

  • Emmmm
    Emmmm almost 2 years

    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.)

  • Amael H.
    Amael H. about 4 years
    Hello, this seems unexact as another post indicates that Nginx has the ability to read the SNI header in the SSL handshake before passing the request to the upstream server : serverfault.com/a/999428