# Default\_server catch all block not working

**URL:** <https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074>\
**Category:** NGINX\
**Created:** [January 24, 2012, 4:26pm UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074 "2012-01-24T16:26:49Z")\
**Posts on this page:** 15\
**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:** [January 24, 2012, 4:26pm UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/1 "2012-01-24T16:26:49Z")

</div>

Hi, getting quite desperate at the moment about this.

I have a server serving several subdomains; actually proxying’em to  
apache2. So I have main nginx vhost file with all server\_name’s added.  
Such server names match the defined ServerName’s and ServerAlias’es of  
Apache.  
Beside, I have one more file to define a default\_server catch all block  
like follows

server {  
listen 80 default\_server;  
server\_name \_;  
error\_log /var/log/nginx/000default-error.log error;  
root /var/www/forvo.com/\_templates;  
error\_page 404 /404.html;  
location / {  
#return 444;  
return 404;  
}  
location = /404.html {  
internal;  
}  
#rewrite .\* [http://myfaultysubdomain.com](http://myfaultysubdomain.com) permanent;  
}

As soon as I enable this file, everything works as expected, however, in  
less than one minute (my site is always being visited), all requests  
(good subdomains and bad subdomains as well) start to get 503 response.  
No log at all seems to change when this happens.

Any clue to what may be happening pleeeeeease …it’s been hours,  
during days, trying to figure out what the h@$!! is going on

Posted at Nginx Forum:

> **[Default\_server catch all block not working](https://forum.nginx.org/read.php?2,221572,221572#msg-221572)**
>
> Hi, getting quite desperate at the moment about this. I have a server serving several subdomains; actually proxying'em to apache2. So I have main nginx vhost file with all server\_name's added. Such server names match the defined ServerName's and...

---

<div class="post-metadata">

**Author:** ![lockev3.0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f08c70/32.png) [@lockev3.0](https://www.ruby-forum.com/u/lockev3.0)\
**Post date:** [January 24, 2012, 4:34pm UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/2 "2012-01-24T16:34:55Z")

</div>

On 24 Jan 2012 15h26 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> server\_name \_;  
> #rewrite .\* [http://myfaultysubdomain.com](http://myfaultysubdomain.com) permanent;  
> }

AFAICT there’s nothing here that should cause the 503s. Do you have  
any limits set, be it connection or rate limit?

— appa

---

<div class="post-metadata">

**Author:** ![lockev3.0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f08c70/32.png) [@lockev3.0](https://www.ruby-forum.com/u/lockev3.0)\
**Post date:** [January 24, 2012, 6:58pm UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/3 "2012-01-24T18:58:32Z")

</div>

glubs !!! header host looks like “the missing culprit”, I’ll check it  
out to confirm your nice guess Mit Rowe

Posted at Nginx Forum:

> **[Re: Default\_server catch all block not working](https://forum.nginx.org/read.php?2,221572,221582#msg-221582)**
>
> Hi, getting quite desperate at the moment about this. I have a server serving several subdomains; actually proxying'em to apache2. So I have main nginx vhost file with all server\_name's added. Such server names match the defined ServerName's and...

---

<div class="post-metadata">

**Author:** ![lockev3.0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f08c70/32.png) [@lockev3.0](https://www.ruby-forum.com/u/lockev3.0)\
**Post date:** [January 24, 2012, 8:51pm UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/4 "2012-01-24T20:51:56Z")

</div>

On 24 Jan 2012 17h57 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> glubs !!! header host looks like “the missing culprit”, I’ll check  
> it out to confirm your nice guess Mit Rowe

444 closes the connection. Doesn’t return any 503 code.

— appa

---

<div class="post-metadata">

**Author:** ![lockev3.0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f08c70/32.png) [@lockev3.0](https://www.ruby-forum.com/u/lockev3.0)\
**Post date:** [January 24, 2012, 5:50pm UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/5 "2012-01-24T17:50:24Z")

</div>

we might need to see your whole configuration to get the full picture,  
but  
here’s an initial thought…

if your apache does virtual hosting based on the Host: header (which  
seems  
likely from your description), you may need to pass the Host: header  
along,  
which you can do like this:

proxy\_set\_header Host $http\_host;

On Tue, Jan 24, 2012 at 10:33 AM, Antnio P. P. Almeida  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)wrote:

> > server {  
> > internal;
> 
> > 
> 
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–  
Will ‘Mit’ Rowe  
Stagename\*  
\*1-866-326-3098  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[www.stagename.com](http://www.stagename.com)  
Twitter: @stagename

_The information transmitted is intended only for the person or entity  
to  
which it is addressed and may contain confidential and/or privileged  
material. Any review, retransmission, dissemination or other use of this  
information by persons or entities other than the intended recipient is  
prohibited. If you received this transmission in error, please contact  
the  
sender and delete all material contained herein from your computer._

---

<div class="post-metadata">

**Author:** ![lockev3.0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f08c70/32.png) [@lockev3.0](https://www.ruby-forum.com/u/lockev3.0)\
**Post date:** [January 25, 2012, 3:51pm UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/6 "2012-01-25T15:51:14Z")

</div>

## António P. P. Almeida Wrote:

> On 24 Jan 2012 17h57 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > glubs !!! header host looks like “the missing  
> > culprit”, I’ll check  
> > it out to confirm your nice guess Mit Rowe
> 
> 444 closes the connection. Doesn’t return any 503  
> code.

I know i know …it’s commented out

> — appa
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,221572,221639#msg-221639](http://forum.nginx.org/read.php?2,221572,221639#msg-221639)

---

<div class="post-metadata">

**Author:** ![lockev3.0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f08c70/32.png) [@lockev3.0](https://www.ruby-forum.com/u/lockev3.0)\
**Post date:** [January 25, 2012, 4:40pm UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/7 "2012-01-25T16:40:07Z")

</div>

Ok as I started thinking later …what for do I need proxy\_set\_header  
if my intention is to not proxy to Apache any request fall onto this  
catch all default\_server ?

To see my config let’s say it is as follow (not all parameters to let it  
be clearer):

====================== /etc/nginx/sites-enabled/mydomain  
server {

```
    listen 80;
    server_name mydomain.com www.mydomain.com sub1.mydomain.com

```

[sub2.mydomain.com](http://sub2.mydomain.com) [sub3.mydomain.com](http://sub3.mydomain.com)  
error\_page 502 503 504 400 /50x.html;  
error\_page 404 /404.php;

```
    large_client_header_buffers 4 4k;

    location = /50x.html {
            root /var/www/mydomain/static/;
    }
    location ~* \.(jpg|jpeg|gif|png|css|bmp|ico|txt|html|swf)$ {

            root /var/www/mydomain/
            expires 1y;
    }
      location / {
            proxy_pass http://127.0.0.1:60080/;
            proxy_redirect off;
         ........
      }

```

}

So my goal is to define a new vhost so that all requests reaching my  
nginx which don’t fit any of my server names (all subdomains) are  
responded as one of 2 :: 404 returned or forwarding to another external  
URL (…whatever it fits better for SEO)

====================== /etc/nginx/sites-enabled/mydomain  
server {  
listen 80 default\_server;  
server\_name \_;  
error\_log /var/log/nginx/000default-error.log error;  
location / {  
proxy\_set\_header Host $host;  
#return 404;  
rewrite .\* [http://doesnotexist.com](http://doesnotexist.com) permanent;  
}  
}

I must say I tested (sure badly i did ) the proxy\_set\_header (not sure  
what for in my case) and still the same behaviour …all my clients  
away ☹

Posted at Nginx Forum:

> **[Re: Default\_server catch all block not working](https://forum.nginx.org/read.php?2,221572,221640#msg-221640)**
>
> Hi, getting quite desperate at the moment about this. I have a server serving several subdomains; actually proxying'em to apache2. So I have main nginx vhost file with all server\_name's added. Such server names match the defined ServerName's and...

---

<div class="post-metadata">

**Author:** ![lockev3.0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f08c70/32.png) [@lockev3.0](https://www.ruby-forum.com/u/lockev3.0)\
**Post date:** [January 25, 2012, 5:17pm UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/8 "2012-01-25T17:17:17Z")

</div>

On 25 Jan 2012 15h39 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> listen 80;  
> location ~\* .(jpg|jpeg|gif|png|css|bmp|ico|txt|html|swf)$ {
> 
> location / {  
> proxy\_set\_header Host $host;  
> #return 404;  
> rewrite .\* [http://doesnotexist.com](http://doesnotexist.com) permanent;  
> }  
> }

This can be made much simpler:

server {  
listen 80 default\_server;  
server\_name \_;

```
error_log /var/log/nginx/000default-error.log error;

return 301 http://doesnotexist.com;

```

}

This redirects to a new host.

For returning a 404 just do:

return 404;

I think that 444 is preferable. No business trying to access a host  
that doesn’t exist. But it’s up to you.

Enable the debug log and set:

proxy\_intercept\_errors on;

Trace the requests and see how are the 503s generated.

> **[A debugging log](http://nginx.org/en/docs/debugging_log.html)**

— appa

---

<div class="post-metadata">

**Author:** ![lockev3.0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f08c70/32.png) [@lockev3.0](https://www.ruby-forum.com/u/lockev3.0)\
**Post date:** [February 1, 2012, 12:32pm UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/9 "2012-02-01T12:32:56Z")

</div>

Ok, first of all thanks a lot Antonio for your answer.  
I’ve followed your instructions adding following block to the very  
beggining of my only one nginx/site-enabled (in just one of my 2  
balanced nginx):

server {  
listen 80 default\_server;  
server\_name \_;  
proxy\_intercept\_errors on;  
error\_log /var/log/nginx/000default-error.log debug;  
access\_log /var/log/nginx/000default-access.log;  
return 444;  
}

below this block came the 3 vhost I serve, all of them with plenty of  
server\_name’s.  
More “clues” I surely shoud have given at my first post ::

.- Architecture :: AWS Elastic Load Balancer ====\> 2 nginx each one  
proxying to its own apache2  
.- My php application relies a lot on apache redirects in htaccess of  
the style: .\*whatever/ .\*whatever.php  
.- As soon as i enable the above block, Server seems to respond Ok but  
the 000default-access.log starts to be filled with:  
…-[A] Plenty of requests responded with the 444 code  
.- [B] Plenty of strange request like this :::  
[01/Feb/2012:12:13:40 +0100] “-” 400 0 “-” “-”

.- In less than 3 minutes, suddenly the above access log stops receiving  
that bunch of 444 responded requests[A] and it only shows the [B] from  
time to time (some buffer overloaded?)

Just to say, the debug level and logs probably I did not use it well as  
it is not adding actual extra info. should it be added to in the rest of  
the server blocks below the default one?

like an X-File to me …don’t know what else to do or try

Posted at Nginx Forum:

> **[Re: Default\_server catch all block not working](https://forum.nginx.org/read.php?2,221572,221854#msg-221854)**
>
> Hi, getting quite desperate at the moment about this. I have a server serving several subdomains; actually proxying'em to apache2. So I have main nginx vhost file with all server\_name's added. Such server names match the defined ServerName's and...

---

<div class="post-metadata">

**Author:** ![lockev3.0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f08c70/32.png) [@lockev3.0](https://www.ruby-forum.com/u/lockev3.0)\
**Post date:** [March 22, 2012, 5:33pm UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/10 "2012-03-22T17:33:01Z")

</div>

At last I got it ! Well, to be honest I will say Maxim Dounim helped me  
thru my logs. In the end it was so simple ::: My load balancer in front  
of my Nginx’s always looked thru IP so no host name ever matched any of  
my server\_name’s. Solution simple :: Do the balancer refer to nodes thru  
a locally resolved hostname also put as a new server\_name.  
…simple like crazyness when it comes.

The thing now is I have following block and it works quite right. But If  
I mean to use the commented return 444 instead of the rewrite ==\> al my  
web start returning 503 !!! and nothing’s functioning …always the  
strange things to me.

server {  
listen 80 default\_server;  
server\_name \_;  
error\_log /var/log/nginx/000default-error.log error;  
location / {  
proxy\_set\_header Host $host;  
rewrite .\* [http://somewherelse.net](http://somewherelse.net) permanent;  
#return 444;  
}  
}

Posted at Nginx Forum:

> **[Re: Default\_server catch all block not working](https://forum.nginx.org/read.php?2,221572,224230#msg-224230)**
>
> Hi, getting quite desperate at the moment about this. I have a server serving several subdomains; actually proxying'em to apache2. So I have main nginx vhost file with all server\_name's added. Such server names match the defined ServerName's and...

---

<div class="post-metadata">

**Author:** ![lockev3.0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f08c70/32.png) [@lockev3.0](https://www.ruby-forum.com/u/lockev3.0)\
**Post date:** [March 28, 2012, 10:12am UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/11 "2012-03-28T10:12:09Z")

</div>

no answers at all ☹

Posted at Nginx Forum:

> **[Re: Default\_server catch all block not working](https://forum.nginx.org/read.php?2,221572,224520#msg-224520)**
>
> Hi, getting quite desperate at the moment about this. I have a server serving several subdomains; actually proxying'em to apache2. So I have main nginx vhost file with all server\_name's added. Such server names match the defined ServerName's and...

---

<div class="post-metadata">

**Author:** ![lockev3.0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f08c70/32.png) [@lockev3.0](https://www.ruby-forum.com/u/lockev3.0)\
**Post date:** [March 28, 2012, 6:11pm UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/12 "2012-03-28T18:11:34Z")

</div>

On 22 March 2012 16:32, lockev3.0 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> strange things to me.  
> }  
> Er, WTF?

You use the non-standard 444 (“444 closes the connection without  
sending any headers”) and you expect your downstream to do something  
with that _other_ than correctly respond to requests with a 503  
Service Unavailable?

What you describe is _exactly_ what I’d expect to see.

Either your understanding/expectations are faulty, or you haven’t  
explained yourself correctly.

Jonathan

---

<div class="post-metadata">

**Author:** ![lockev3.0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f08c70/32.png) [@lockev3.0](https://www.ruby-forum.com/u/lockev3.0)\
**Post date:** [February 2, 2012, 1:11pm UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/13 "2012-02-02T13:11:07Z")

</div>

please help  
this bothering X-File is causing crawlers to index my site with plenty  
of non-existent subdomains …

Posted at Nginx Forum:

> **[Re: Default\_server catch all block not working](https://forum.nginx.org/read.php?2,221572,221905#msg-221905)**
>
> Hi, getting quite desperate at the moment about this. I have a server serving several subdomains; actually proxying'em to apache2. So I have main nginx vhost file with all server\_name's added. Such server names match the defined ServerName's and...

---

<div class="post-metadata">

**Author:** ![lockev3.0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f08c70/32.png) [@lockev3.0](https://www.ruby-forum.com/u/lockev3.0)\
**Post date:** [April 16, 2012, 10:44am UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/14 "2012-04-16T10:44:29Z")

</div>

Well, probably I’m, still novice at Nginx but, that default server block  
is meant to fit when no other block server (server\_name) fits. So my  
current problem is that 444 behaviour is arising all thru my nginx  
server, not just that default\_server block/vhost  
…not quit sure If I explained my self better now ? or even  
understood you right …

Posted at Nginx Forum:

> **[Re: Default\_server catch all block not working](https://forum.nginx.org/read.php?2,221572,225354#msg-225354)**
>
> Hi, getting quite desperate at the moment about this. I have a server serving several subdomains; actually proxying'em to apache2. So I have main nginx vhost file with all server\_name's added. Such server names match the defined ServerName's and...

---

<div class="post-metadata">

**Author:** ![lockev3.0](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f08c70/32.png) [@lockev3.0](https://www.ruby-forum.com/u/lockev3.0)\
**Post date:** [April 19, 2012, 2:37pm UTC](https://www.ruby-forum.com/t/default-server-catch-all-block-not-working/216074/15 "2012-04-19T14:37:26Z")

</div>

Hello!

On Mon, Apr 16, 2012 at 04:43:46AM -0400, lockev3.0 wrote:

> Well, probably I’m, still novice at Nginx but, that default server block  
> is meant to fit when no other block server (server\_name) fits. So my  
> current problem is that 444 behaviour is arising all thru my nginx  
> server, not just that default\_server block/vhost  
> …not quit sure If I explained my self better now ? or even  
> understood you right …

I belive Jonathan M. is right and the problem is as follows:  
your load balancer sees invalid response from your nginx server  
(as “return 444” just drops the connection) and starts to think  
it’s not working (and starts to return errors to clients without  
even asking nginx).

There are two possible solutions:

1. Don’t use “return 444” but return some correct response. In  
any case “return 444” doesn’t help at all as long as your nginx is  
behind load balancer (as your balancer will return response  
anyway).

2. Tune your balancer to ignore such connection closes (not sure  
this is possible).

Maxim D.
