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