Trying to do the opposite of www.domain.com -> domain.com

Igor Sysoev is at rambler-co.ru
Mon Sep 1 11:34:37 MSD 2008


On Mon, Sep 01, 2008 at 12:29:44AM -0700, mike wrote:

> On 9/1/08, Igor Sysoev <is at rambler-co.ru> wrote:
> 
> > Just for info, here is some configuration that returns 404 for any invalid
> > hostname if you do not want to associate your site with these names:
> >
> >     server {
> >         listen 80 default;
> >         server_name _;
> >         return  404;
> >     }
> 
> this would probably work to log any unknown host headers/missing host
> headers, right?
> 
>         server {
>                 listen 80 default;
>                 server_name _;
>                 return 404;
>                 access_log /var/log/nginx/unmapped.log;
>                 root /htdocs/unmapped/;
>         }

Yes.

> another question:
> 
> is there any reason to require the ending slash "/" ?
>                 root /htdocs/unmapped/;
> as opposed to:
>                 root /htdocs/unmapped;
> 
> i used to think it was required but it seems to work properly now
> without the slash too.

There is no difference for "root" directive. Actually, nginx deletes
trailing slash from "root" directive because $request_file_name is
$document_root$uri", and $uri has slash as first character.

But the trailing slash is important for "alias" directive, because
"alias" literally replaces location part of URI:

location /dir/ {
     alias  /path/to/;
}

/dir/file > /path/to/file


-- 
Igor Sysoev
http://sysoev.ru/en/





More information about the nginx mailing list