How to make nginx to listen to server_name:port

后端 未结 1 1347
天涯浪人
天涯浪人 2020-12-25 10:16

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.

相关标签:
1条回答
  • 2020-12-25 10:45

    The server_namedocs 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 listendocs 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).

    0 讨论(0)
提交回复
热议问题