Welcome! Log In Create A New Profile

Advanced

server_name '_' and custom error_page

Mark Bekkers
October 29, 2010 06:50AM
Hi,

This is my first time post, hi everybody.

The reason of this post is that I found some Nginx behaviour that I
don't understand.
I would like to know if it's a bug or not.
Version: nginx/0.8.52

I pointed all DNS requests to my Nginx server (using a CNAME wildcard).
Every none matched server names are handled by the snippit below (a
fallback server configuration)

server {
# CONFIG
server_name _;

# SETTINGS
listen 80 default;
root /var/www/host/default/public;
access_log /var/www/home/log/nginx/default.access.log;

error_page 404 /error_page/404.html;
location /error_page/ {alias /var/www/home/error_page/; allow all;
internal;}

}


A request to kjhtgfcdh.example.com will be catched by the fallback
configuration and then serves
my custom defined 404 because the root directive points to an empy
directory; thus no file is found.

This way I can inform clients (with a custom error_page) they are
accessing the wrong host.

But this seemed wrong so I changed it to:

server {
# CONFIG
server_name _;

# SETTINGS
listen 80 default;
access_log /var/www/home/log/nginx/default.access.log;

error_page 404 /error_page/404.html;
location /error_page/ {alias /var/www/home/error_page/; allow all;
internal;}

return 404;

}

This is almost the same, but it has no root directive and a return
directive.
This seems the way to do it because it skips the need to look for a file
in the root and returns with a 404
immediately, but it doesn't serve my custom error_page. It serves the
nginx internal 404 document.

So I changed it to:

server {
# CONFIG
server_name _;

# SETTINGS
listen 80 default;
access_log /var/www/home/log/nginx/default.access.log;

error_page 404 /error_page/404.html;
location /error_page/ {alias /var/www/home/error_page/; allow all;
internal;}

location / {
return 404;
}

}

Again no root directive but the return directive is wrapped in a
location block and it DOES
serve my custom error_page.

My questions:
Did I found a bug? And if I did; what would be correct behaviour?
And if I did not; what is the correct behaviour in this context?


- Mark






_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

server_name '_' and custom error_page

Mark Bekkers October 29, 2010 06:50AM

Re: server_name '_' and custom error_page

Maxim Dounin October 29, 2010 07:06AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 165
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready