error_page

Witold Filipczyk witekfl001 at gmail.com
Wed Oct 20 21:03:37 MSD 2010


On Wed, Oct 20, 2010 at 08:25:42PM +0400, Maxim Dounin wrote:
> Hello!
> 
> On Wed, Oct 20, 2010 at 05:58:09PM +0200, witekfl at gazeta.pl wrote:
> 
> > On Wed, Oct 20, 2010 at 07:21:19PM +0400, Igor Sysoev wrote:
> > > On Wed, Oct 20, 2010 at 05:10:59PM +0200, witekfl Gazeta.pl wrote:
> > > 
> > > > Hi,
> > > > probably better place for these questions would be nginx-users, but I ask
> > > > here.
> > > > I want to serve static pages as error codes but without changing the error
> > > > code.
> > > > 
> > > > Now if:
> > > > error_page 404 http://blablabla.com/404.html
> > > > There is 302 and next 200 OK
> > > > I want 404.
> > > > 
> > > > error_page 404 /404.html
> > > > it works, but:
> > > > if there is:
> > > > location = /404.html {
> > > > internal;
> > > > }
> > > > then cannot be a normal location
> > > > location = /404.html {
> > > > },
> > > > so request such as http://blabla1.com/404.html won't work.
> > > > 
> > > > error_page 404 @404;
> > > > location @404 {
> > > >    root /blabla;
> > > >    index 404.html;
> > > > }
> > > > doesn't work either
> > > > 
> > > > There must be some way to achieve it.
> > > > How?
> > > 
> > > I do not understand the problem. With this configuration
> > > 
> > > error_page  404 /404.html;
> > > locaiton = /404.html {
> > >     internal;
> > >     root /path/to/page;
> > > }
> > > 
> > > you will get 404 code with /404.html body for both requests:
> > > 
> > > http://blabla1.com/non-existant.html
> > > http://blabla1.com/404.html
> > 
> > Yes, but I want:
> > http://blabla1.com/404.html to be 200 OK and serve http://blabla1.com/404.html
> > not /path/to/page/404.html
> 
> Something like this:
> 
>     error_page 404 @notfound;
> 
>     location @notfound {
>         rewrite ^ /404.html break;
>         root /path/to/page;
>     }
> 
> should do the trick.

Yes, it works. Thanks!
Could you explain, why it works.
Why this rewrite is required?
Does it mean that for 404 by default /404.html is requested or not?




More information about the nginx-devel mailing list