why is nginx binding to 0.0.0.0:80 when I specify explicit IPs to listen on?

Igor Sysoev igor at sysoev.ru
Wed Jan 23 05:09:03 UTC 2013


On Jan 23, 2013, at 2:15 , middleforkgis wrote:

> I'm having a difficult time understanding why I'm unable to limit the IP
> address to which nginx binds.
> 
> nginx                          1.2.6-1
> Linux 3.2.0-4-amd64 #1 SMP Debian 3.2.35-2 x86_64 GNU/Linux
> 
> 
> ================
> root at skokomish:/etc/nginx# netstat -pant |grep nginx
> tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN  
>   7768/nginx      
> tcp        0      0 66.113.100.140:81       0.0.0.0:*               LISTEN  
>   7768/nginx      
> 
> shows that it is binding on port 80 of all IP addresses.
> =================
> Yet each of my hosts is explicitly listening on a single IP address:
> 
> root at skokomish:/etc/nginx/sites-available# more default
> { listen 127.0.0.1:80; }
> =================
> root at skokomish:/etc/nginx/sites-available# more example
> server
> {
>    server_name example.com www.example.com;
>    listen 66.113.100.140:80;
>    access_log /var/log/ngnix/example.log;
>    error_log /var/log/nginx/example.error.log;
> 
>   location /site {
>   	alias /data/www/content/site/example;
> 	}  
>   location / {
>        proxy_pass_header Server;
>        proxy_set_header Host $http_host;
>        proxy_redirect off;
>        proxy_set_header X-Real-IP $remote_addr;
>        proxy_set_header X-Scheme $scheme;
>        proxy_connect_timeout 10;
>        proxy_read_timeout 10;
>       	proxy_pass http://10.15.20.10:8107/;
>    }	
> }
> 
> 
> ==========================
> There is no 'listen' statement in nginx.conf itself:
> root at skokomish:/etc/nginx# grep listen nginx.conf
> #		listen     localhost:110;
> #		listen     localhost:143;
> ==========================
> Grepping for 'listen' shows:
> 
> root at skokomish:/etc/nginx# for i in `find .`; do grep listen $i;
> done|sort|uniq
> grep: .: Is a directory
> grep: ./sites-enabled: Is a directory
> grep: ./conf.d: Is a directory
> grep: ./sites-available: Is a directory
> { listen 127.0.0.1:80; }
>    listen 66.113.100.140:80;
> 	listen 66.113.100.140:81;
> #		listen     localhost:110;
> #		listen     localhost:143;
> root at skokomish:/etc/nginx# ls conf.d
> root at skokomish:/etc/nginx# 
> 
> ==================================
> Thanks in advance.

If there is server block without a listen directive,
then nginx will listen on *:80.


--
Igor Sysoev
http://nginx.com/support.html



More information about the nginx mailing list