Deny all + Custom Error page

Jonathan Matthews contact at jpluscplusm.com
Fri Jun 6 09:24:10 UTC 2014


On 6 Jun 2014 08:49, "basti" <black.fledermaus at arcor.de> wrote:
>
> 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'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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20140606/1b0b872e/attachment.html>


More information about the nginx mailing list