Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 935
Emmmm Avatar asked Jul 21 '17 01:07

Emmmm


People also ask

What is server_name _ in nginx?

server { listen 80; server_name example.org www.example.org ""; ... } If no server_name is defined in a server block then nginx uses the empty name as the server name. nginx versions up to 0.8. 48 used the machine's hostname as the server name in this case. If a server name is defined as “ $hostname ” (0.9.

Can Nginx TCP proxy?

Load balancing refers to efficiently distributing network traffic across multiple backend servers. In NGINX Plus Release 5 and later, NGINX Plus can proxy and load balance Transmission Control Protocol) (TCP) traffic. TCP is the protocol for many popular applications and services, such as LDAP, MySQL, and RTMP.

Does order matter in Nginx config?

Yes, it does and totally depends on different directives specified within the different context supported by Nginx.

What does Proxy_pass do in nginx?

The proxy_pass setting makes the Nginx reverse proxy setup work. The proxy_pass is configured in the location section of any virtual host configuration file. To set up an Nginx proxy_pass globally, edit the default file in Nginx's sites-available folder.


1 Answers

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

like image 164
Emmmm Avatar answered Sep 19 '22 01:09

Emmmm