derRobert
derRobert

Reputation: 571

nginx custom error page for all requests

i try to provide a custom 404 for all requests in a vhost, Tried:

server {
   ...
   root /var/www;
   error_page 404 /404.html;
   location / {
     return 404;
   }
}

Also tried to put the file outside webroot:

server {
   ...
   root /var/www;
   error_page 404 /var/404.html;
   location / {
     return 404;
   }
}

Or

server {
   ...
   root /var/www;       
   location / {
     error_page 404 /var/404.html;
     return 404;
   }
}

With no luck .... Any ideas?

Upvotes: 2

Views: 1128

Answers (1)

derRobert
derRobert

Reputation: 571

like @Richard Smith commented:

server {
  ...
  root /var/www;     
  error_page 404 /404.html;  
  location / {     
    return 404;
  }
  location = /404.html {
    internal;
  }
}

Works !

Upvotes: 4

Related Questions