In my nginx conf file, I have :
listen 80; server_name $hostname;
however if I do netstat I see that it is listening on 0.0.0.0:80
what I want to happen, is the nginx to listen to $hostname:80 , is there a way to configure it to do that?
I tried different settings with no success so far. Appreciate your help.
By default, the Nginx HTTP server listens for inbound connections and connects to port 80, which is the default web port. However, the TLS configuration, which is not supported in Nginx by default, listens to port 443 for secure connections.
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.
Here, the server name is set to an empty string that will match requests without the “Host” header field, and a special nginx's non-standard code 444 is returned that closes the connection. On the other side, server_name _; defines an invalid server names which never intersect with any real name.
The server_name
docs directive is used to identify virtual hosts, they're not used to set the binding.
netstat
tells you that nginx listens on 0.0.0.0:80
which means that it will accept connections from any IP.
If you want to change the IP nginx binds on, you have to change the listen
docs rule.
So, if you want to set nginx to bind to localhost
, you'd change that to:
listen 127.0.0.1:80;
In this way, requests that are not coming from localhost are discarded (they don't even hit nginx).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With