server_name
The 'server_name' directive specifies the hostnames for which a server block should respond in NGINX.
Description
The 'server_name' directive plays a crucial role in configuring server blocks by defining the hostnames that should trigger the specific configuration of an NGINX server. This directive accepts one or more arguments, typically in the form of domain names, IP addresses, or wildcards. By utilizing wildcards, such as *.example.com, NGINX can match multiple subdomains dynamically, making it a versatile tool in managing requests for different hosts.
When a request is received, NGINX evaluates the 'Host' header in the HTTP request against the 'server_name' values defined across all server blocks. It chooses the most specific match available. If no match is found, NGINX defaults to a fallback server block, which is usually configured to listen to any hostname, resulting in an error response or redirection, depending on the configuration.
In a media streaming context as provided by the 'nginx-module-rtmp', the 'server_name' directive configures which hostnames are allowed to connect to the RTMP server streams. Proper configuration can help manage and secure media delivery, allowing administrators to restrict access to only specific domains while improving manageability of multiple streams hosted on the same server.
Config Example
server {
listen 1935;
server_name example.com *.example.com;
application live {
live on;
}
}Using improper syntax for wildcards may lead to unexpected behavior.
The order of server_name directives can affect request matching in complex configurations.
Ensure that only valid and intended hostnames are configured to prevent unauthorized access.