# Deny all + Custom Error page

**URL:** <https://www.ruby-forum.com/t/deny-all-custom-error-page/230246>\
**Category:** NGINX\
**Created:** [June 6, 2014, 9:49am UTC](https://www.ruby-forum.com/t/deny-all-custom-error-page/230246 "2014-06-06T09:49:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jason\_sam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7993a0/32.png) [@jason\_sam](https://www.ruby-forum.com/u/jason_sam)\
**Post date:** [June 6, 2014, 9:49am UTC](https://www.ruby-forum.com/t/deny-all-custom-error-page/230246/1 "2014-06-06T09:49:24Z")

</div>

Hello,

I try to block wildcard sub domains as follows:

# block wildcard

server {  
server\_name ~^(.\*).example.com$ ;  
root /usr/share/nginx/www;  
error\_page 403 /index.html;  
allow 127.0.0.1;  
deny all;  
access\_log off;  
log\_not\_found off;  
}

I always get the default “403 Forbidden” site of nginx.  
When “deny all” is removed it work as expected.

Can anybody explain?  
And does anybody know a workaround?

Best Regards;  
Basti

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 6, 2014, 10:58am UTC](https://www.ruby-forum.com/t/deny-all-custom-error-page/230246/2 "2014-06-06T10:58:20Z")

</div>

Here is my solution:

server {  
server\_name ~^(.\*).example.com$ ;  
return 200;  
deny all;  
access\_log off;  
log\_not\_found off;  
}

Am 06.06.2014 09:48, schrieb basti:

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 6, 2014, 11:24am UTC](https://www.ruby-forum.com/t/deny-all-custom-error-page/230246/3 "2014-06-06T11:24:52Z")

</div>

On 6 Jun 2014 08:49, “basti” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> error\_page 403 /index.html;  
> allow 127.0.0.1;  
> deny all;  
> access\_log off;  
> log\_not\_found off;  
> }

I’m sure there’s a precedence rule that’ll explain this but I don’t have  
it  
to hand.

However, have you considered merely telling that server{} to listen only  
on  
127.0.0.1?

You may also wish to look at the server\_name documentation for the  
shorthand of “\*.foo.com” instead of the regex you’re using.

Finally, if your aim is just to deny requests for hosts you haven’t  
explicitly configured elsewhere in nginx’s config file, I find the  
following to be a useful catchall. Use it alongside well-defined  
server\_names in other server blocks.

server {  
listen 80 default\_server;  
server\_name \_;  
location / { return 404; }  
}

HTH,  
J
