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

**URL:** <https://www.ruby-forum.com/t/how-to-prevent-processing-requests-with-undefined-server-names-on-nginx-1-1-17/218254>\
**Category:** NGINX\
**Created:** [March 26, 2012, 1:33pm UTC](https://www.ruby-forum.com/t/how-to-prevent-processing-requests-with-undefined-server-names-on-nginx-1-1-17/218254 "2012-03-26T13:33:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 26, 2012, 1:33pm UTC](https://www.ruby-forum.com/t/how-to-prevent-processing-requests-with-undefined-server-names-on-nginx-1-1-17/218254/1 "2012-03-26T13:33:55Z")

</div>

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;

```

}

server {

```
     listen 192.168.1.3:80 default_server;

     server_name www1.domain1.com;

     access_log /var/log/nginx/www1.domain1.com.access.log main;

     location / {

          include proxy.conf;

     proxy_pass http://127.0.0.1:8080;

     }

     }

```

server {

```
     listen 192.168.1.3:80;

     server_name forum.domain1.com;

     access_log /var/log/nginx/forum.domain1.com.access.log main;

     location / {

          include proxy.conf;

     proxy_pass http://127.0.0.1:8080;

     }

     }

```

server {

```
     listen 192.168.1.3:80;

     server_name www.domain1.com domain1.com;

     access_log /var/log/nginx/www.domain1.com.access.log main;

     location / {

          include proxy.conf;

     proxy_pass http://127.0.0.1:8080;

     }

     }

```

server {

```
     listen 192.168.1.3:80;

     server_name www.domain2.com domain2.com;

     access_log /var/log/nginx/www.domain2.com.access.log main;

     location / {

          include proxy.conf;

     proxy_pass http://127.0.0.1:8080;

     }

     }

```

My problem:

When I access undefined server names, ex: [anything.domain1.com](http://anything.domain1.com) or  
[anything.domain2.com](http://anything.domain2.com)

I can still access, I want it to return 444.

How I fix my problem ???

Thank all team Nginx,

Nguyen

---

<div class="post-metadata">

**Author:** ![HKS\_VIETNAM](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/838e76/32.png) [@HKS\_VIETNAM](https://www.ruby-forum.com/u/HKS_VIETNAM)\
**Post date:** [March 26, 2012, 1:45pm UTC](https://www.ruby-forum.com/t/how-to-prevent-processing-requests-with-undefined-server-names-on-nginx-1-1-17/218254/2 "2012-03-26T13:45:04Z")

</div>

Try:

server {  
listen [::]:80 default\_server;  
server\_name \_;  
return 444;  
}

You’ll have to define _all valid_ hosts in each server block.

–appa

---

<div class="post-metadata">

**Author:** ![HKS\_VIETNAM](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/838e76/32.png) [@HKS\_VIETNAM](https://www.ruby-forum.com/u/HKS_VIETNAM)\
**Post date:** [March 26, 2012, 1:48pm UTC](https://www.ruby-forum.com/t/how-to-prevent-processing-requests-with-undefined-server-names-on-nginx-1-1-17/218254/3 "2012-03-26T13:48:51Z")

</div>

> Apache listen on: 8080
> 
> proxy\_buffer\_size 16k;

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 [Server names](http://nginx.org/en/docs/http/server_names.html)

---

<div class="post-metadata">

**Author:** ![HKS\_VIETNAM](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/838e76/32.png) [@HKS\_VIETNAM](https://www.ruby-forum.com/u/HKS_VIETNAM)\
**Post date:** [March 26, 2012, 6:15pm UTC](https://www.ruby-forum.com/t/how-to-prevent-processing-requests-with-undefined-server-names-on-nginx-1-1-17/218254/4 "2012-03-26T18:15:56Z")

</div>

Dear,

Thank you so much.

It’s OK 🙂 My proplem has been fixed.

Thank you,  
Nguyen
