How to prevent processing requests with undefined server names on nginx 1.1.17

Alexander Kolesen kolesen.a at gmail.com
Mon Mar 26 11:48:27 UTC 2012


> Dear Team,
> 
>  
> 
> My OS: Centos 5.8
> 
> My nginx 1.1.7
> 
>  
> 
> Apache listen on: 8080
> 
> Nginx listen on: 80
> 
>  
> 
> nginx as reverse proxy.
> 
>  
> 
> My proxy.conf file
> 
> proxy_redirect off;
> proxy_set_header Host $host;
> proxy_set_header X-Real-IP $remote_addr;
> proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
> client_max_body_size 10m;
> client_body_buffer_size 128k;
> client_header_buffer_size 64k;
> proxy_connect_timeout 90;
> proxy_send_timeout 90;
> proxy_read_timeout 90;
> proxy_buffer_size 16k;
> proxy_buffers 32 16k;
> proxy_busy_buffers_size 64k;
> 
>                                                        
> 
> My nginx config file:
> 
>  
> 
> server {
> 
>      listen       80;
> 
>      server_name  "";
> 
>      return       444;
> 
> }
> 
>  
> 
>  
>


Just rewrite your "catch all" virtual host as a following:

server {
    listen       80 default_server;
    server_name  _;
    return       444;
}

And move 'default_server' attribute here, from your second virtual host.


Note that the 'server_name  ""' syntax means 'empty Host header'. 
But it will work with the 'listen 80 default_server'.

Refer the http://nginx.org/en/docs/http/server_names.html



More information about the nginx mailing list