# Custom error pages - current limitations

**URL:** <https://www.ruby-forum.com/t/custom-error-pages-current-limitations/146463>\
**Category:** NGINX\
**Created:** [August 21, 2008, 11:53am UTC](https://www.ruby-forum.com/t/custom-error-pages-current-limitations/146463 "2008-08-21T11:53:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luigi\_Perroti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c89c15/32.png) [@Luigi\_Perroti](https://www.ruby-forum.com/u/Luigi_Perroti)\
**Post date:** [August 21, 2008, 11:53am UTC](https://www.ruby-forum.com/t/custom-error-pages-current-limitations/146463/1 "2008-08-21T11:53:33Z")

</div>

Hi,

I’m rather new to nginx and I would like to have a confirmation that  
the following scenarios can’t be handled with the current  
implementation.

1. When a client sends a request without the Host: header nginx  
returns an hardcoded 400 response.  
Actually it isn’t possible to use a custom error page in this situation.  
I tried to handle this using the “root” and “error\_page” directives in  
the http section but it didn’t work.

2. Consider this simple config file snippet. It’s from a configuration  
file with only one server, every request is passed to a fastcgi server  
which always processes the same script:

server {  
…  
location / {  
fastcgi\_pass 127.0.0.1:1234;  
fastcgi\_param SCRIPT\_FILENAME /script.php;  
fastcgi\_param SCRIPT\_NAME script.php;  
fastcgi\_intercept\_errors off;  
…  
}

}

From what you can see I want to handle all kinds of error codes from the  
script.  
Still there is an exception to that, the “500 Internal server error”  
response.

If the fastcgi server returns this error nginx will do nothing and  
each browser will handle this situation differently.

If I’m not mistaken there is no way for me to define a custom error  
page that will be triggered only for the 500 code.  
In fact, if I set “fastcgi\_intercept\_errors on;” nginx will also  
handle all the other error codes.

Is there any workaround to handle these scenarios?

Maybe having a directive in the http section that maps a certain  
status code to a static file could be useful in these situations and  
more.

No matter what, before returning the page to the client check if the  
status code is handled by this directive. If it is simply return the  
associated file as the response body.

Moreover it should also be possible to define an absolute path for the  
file, independently from the document root. To avoid having to mess  
with the “internal” directive.

I suppose that when this feature is enabled performance would take a  
hit, but I’d accept this gladly for the increased versatility.

Any consideration would be most welcome, thanks!

Regards,  
-Luigi

---

<div class="post-metadata">

**Author:** ![Luigi\_Perroti](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/c89c15/32.png) [@Luigi\_Perroti](https://www.ruby-forum.com/u/Luigi_Perroti)\
**Post date:** [August 21, 2008, 12:11pm UTC](https://www.ruby-forum.com/t/custom-error-pages-current-limitations/146463/2 "2008-08-21T12:11:10Z")

</div>

On Thu, Aug 21, 2008 at 11:44:04AM +0200, Luigi Perroti wrote:

> I’m rather new to nginx and I would like to have a confirmation that  
> the following scenarios can’t be handled with the current  
> implementation.
> 
> 1. When a client sends a request without the Host: header nginx  
> returns an hardcoded 400 response.  
> Actually it isn’t possible to use a custom error page in this situation.  
> I tried to handle this using the “root” and “error\_page” directives in  
> the http section but it didn’t work.

The following should work:

http {

```
 error_page 400 /400.html;

 server {
     listen 80 default;

     location = /400.html {
         root /path/to/page;
     }
 }

 server {
     listen 80;
     ...

```

Often the 400 error is handled in default server context.

> ```
> fastcgi_intercept_errors off;
> 
> ```
> 
> If I’m not mistaken there is no way for me to define a custom error  
> page that will be triggered only for the 500 code.  
> In fact, if I set “fastcgi\_intercept\_errors on;” nginx will also  
> handle all the other error codes.
> 
> Is there any workaround to handle these scenarios?

```
location / {
    ...
    fastcgi_intercept_errors on;

    error_page 502 504 /errors/502.html;
    error_page 500 /errors/500.html;
}

location /errors/ {
    root /path/to/pages;
}

```

fastcgi\_intercept\_errors intercepts only errors those have error\_page  
handlers. Other will go as is from PHP.
