Custom error pages files

probegin

Verified User
Joined
Jun 25, 2015
Messages
7
Hello,

I've created the following error pages:
Code:
400.php
401.php
403.php
404.php
500.php

Like you can see they're not the default .shtml extenstion. I tried to search where nginx includes these default error pages unfortunately I was not able to find it on my CentOS machine. I thought it might have some default error pages where you don't have to point nginx at, using directives in some kind of .conf file. So I tried to override this default configuration by added the following to /etc/nginx/nginx.conf.
Code:
error_page 400 /400.php;
error_page 401 /401.php;
error_page 403 /403.php;
error_page 404 /404.php;
error_page 500 /500.php;

Unfortunately nothing changed. What am I doing wrong? Is it possible to use .php error pages?
 
Someone on IRC suggest me to change the paths in the nginx.conf file. To the right directory:

Code:
error_page 400 /usr/local/directadmin/data/templates/default/400.php;
error_page 401 /usr/local/directadmin/data/templates/default/401.php;
error_page 403 /usr/local/directadmin/data/templates/default/403.php;
error_page 404 /usr/local/directadmin/data/templates/default/404.php;
error_page 500 /usr/local/directadmin/data/templates/default/500.php;

Still no luck, the error pages are still the default. For example when I visit test.local/does-not-exist, then it still shows the default error page:

404 Not Found
nginx​

I can't find this template anywhere on my system, neither a directive pointing to it.

Any clues?
 
Hello,

Try this guide:

- How To Configure Nginx to Use Custom Error Pages on Ubuntu 14.04https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-to-use-custom-error-pages-on-ubuntu-14-04


Check the guide and remember paths are different from those which are used on Directadmin powered server.
The main idea is that you should re-define Location for the purpose.

First try to use Custom Code section in Directadmin and do not change templates. You can use CUSTOM, CUSTOM3, CUSTOM4 for that.
 
Thanks for the reply Alex,

Unfortunately I wasn't able to make it work.

What I did:

  • Copied the error pages files to "/opt", an empty folder.
  • Changed my config to the following at /etc/nginx/nginx-includes.conf (included in the nginx.conf):
    Code:
    server {
            listen 80 default_server;
            listen [::]:80 default_server ipv6only=on;
            error_page 404 /404.php;
            location = /404.php {
                    root /opt;
                    internal;
            }
            ...
    }
  • Restarted nginx.
  • Visited one of a random user's domain 404 pages.

..same output as described in previous post.
 
The /var/log/nginx/error_log doesn't seem to log anything about error pages. It looks like that nginx `'just doesn't want to listen'`, it selfishly chooses to use the default nginx error page over and over again.
 
Back
Top