Default_server catch all block not working

15 views
Skip to first unread message

lockev3.0

unread,
Jan 24, 2012, 10:26:29 AM1/24/12
to ng...@nginx.org
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 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: http://forum.nginx.org/read.php?2,221572,221572#msg-221572

_______________________________________________
nginx mailing list
ng...@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx

António P. P. Almeida

unread,
Jan 24, 2012, 10:33:55 AM1/24/12
to ng...@nginx.org
On 24 Jan 2012 15h26 WET, nginx...@nginx.us wrote:

> 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 permanent;
> }

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

--- appa

Mit Rowe

unread,
Jan 24, 2012, 11:49:59 AM1/24/12
to ng...@nginx.org
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;
--
Will 'Mit' Rowe
Stagename

1-866-326-3098
m...@stagename.com
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. 

lockev3.0

unread,
Jan 24, 2012, 12:57:48 PM1/24/12
to ng...@nginx.org
glubs !!! header host looks like "the missing culprit", I'll check it
out to confirm your nice guess Mit Rowe

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,221572,221582#msg-221582

António P. P. Almeida

unread,
Jan 24, 2012, 2:51:25 PM1/24/12
to ng...@nginx.org
On 24 Jan 2012 17h57 WET, nginx...@nginx.us 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

lockev3.0

unread,
Jan 25, 2012, 9:50:47 AM1/25/12
to ng...@nginx.org
António P. P. Almeida Wrote:
-------------------------------------------------------

> On 24 Jan 2012 17h57 WET, nginx...@nginx.us
> 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
> ng...@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx

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

lockev3.0

unread,
Jan 25, 2012, 10:39:46 AM1/25/12
to ng...@nginx.org
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 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 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: http://forum.nginx.org/read.php?2,221572,221640#msg-221640

António P. P. Almeida

unread,
Jan 25, 2012, 11:16:30 AM1/25/12
to ng...@nginx.org

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.

http://nginx.org/en/docs/debugging_log.html

--- appa

lockev3.0

unread,
Feb 1, 2012, 6:32:35 AM2/1/12
to ng...@nginx.org
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: http://forum.nginx.org/read.php?2,221572,221854#msg-221854

lockev3.0

unread,
Feb 2, 2012, 7:10:17 AM2/2/12
to ng...@nginx.org
please help
this bothering X-File is causing crawlers to index my site with plenty
of non-existent subdomains ....

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,221572,221905#msg-221905

lockev3.0

unread,
Mar 22, 2012, 12:32:11 PM3/22/12
to ng...@nginx.org
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 permanent;
#return 444;
}
}

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,221572,224230#msg-224230

Jonathan Matthews

unread,
Mar 28, 2012, 12:10:59 PM3/28/12
to ng...@nginx.org
On 22 March 2012 16:32, lockev3.0 <nginx...@nginx.us> wrote:
> 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 permanent;
>                #return 444;
>        }
> }


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

Reply all
Reply to author
Forward
0 new messages