nginx - cannot get custom 404 page to work

Issues related to applications and software problems
Post Reply
fishface
Posts: 27
Joined: 2016/08/02 15:47:42

nginx - cannot get custom 404 page to work

Post by fishface » 2018/10/26 13:23:21

I have a nginx configured to work using ssl with self-signed certs (it's a dev box) serving static content and it works fine, however I cannot get the custom 404 page to work, which should be very straight forward but I'm obviously missing something.

I have added a custom_404.html page to /usr/share/nginx/html/ and added the appropriate lines to the conf file, but when testing it still displays the default 404, and the odd thing is, even if I rename the 404.html page it still does it. I've stopped/started nginx, cleared browser cache etc. Is the default 404 complied into nginx or something?

I have blocked port 80 (iptables) and disabled http completely, and I was wondeiring if this has caused the issue, that 404 pages have to be over http?

Complete newbie to nginx, no doubt I'm doing something wrong!

Here is my conf file

Code: Select all

# Settings for a TLS enabled server.
#
    server {
        listen       443 ssl;
        server_name  byron.local;
        keepalive_timeout 70;
        root         /var/www/html;

#       Turned off server tokens to obfuscate nginx verion
        server_tokens off; 

        ssl_certificate "/etc/pki/tls/certs/byron.local.crt";
        ssl_certificate_key "/etc/pki/tls/private/byron.local.key";

#       Added dhparam to increase security
        ssl_dhparam /etc/pki/tls/certs/dhparam.pem;

        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;

#       Lets disabe crap ciphers
#        ssl_ciphers HIGH:!aNULL:!MD5;
#       ...and use strong ones
        ssl_ciphers ECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH;
        ssl_prefer_server_ciphers on;

#       Lets disable unsafe protocols
        #ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_protocols TLSv1.2;
#
#        # Load configuration files for the default server block.
#        include /etc/nginx/default.d/*.conf;
#
#        location / {
#        }

        error_page 404 /custom_404.html;
            location = /custom_404.html {
        root   /usr/share/nginx/html;
               internal;
        }
#       Don't need so many error pages
#        error_page 500 502 503 504 /50x.html;
#            location = /50x.html {
        }

Code: Select all

[root@byron conf.d]# cd /usr/share/nginx/html/
[root@byron html]# ls -l
total 28
-rw-r--r-- 1 root root 3724 Oct 25 14:52 404.html.disabled
-rw------- 1 root root 3650 Oct 25 14:52 404.html.sterile
-rw-r--r-- 1 root root 3693 Mar  6  2018 50x.html
-rw-r--r-- 1 root root 3724 Oct 25 14:34 custom_404.html
-rw-r--r-- 1 root root 3700 Mar  6  2018 index.html
-rw-r--r-- 1 root root  368 Mar  6  2018 nginx-logo.png
-rw-r--r-- 1 root root 2811 Mar  6  2018 poweredby.png

Code: Select all

Something has triggered missing webpage on your website. This is the default 404 error page for nginx that is distributed with Fedora. It is located /usr/share/nginx/html/404.html

You should customize this error page for your own site or edit the error_page directive in the nginx configuration file /etc/nginx/nginx.conf.

Code: Select all

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;

    include /etc/nginx/default.d/*.conf;

    }

fishface
Posts: 27
Joined: 2016/08/02 15:47:42

Re: nginx - cannot get custom 404 page to work

Post by fishface » 2018/10/30 17:40:30

If I go directly to https://byron.local/custom_404.html it now works, but if I test it by adding random page, for example, https://byron.local:/random_page.html I get the "404 Page Not Found" with "ngix" under it.

Post Reply