404 page not working Nginx Ubuntu with letsencrypt installed

November 16, 2016 79 views
Let's Encrypt Nginx Node.js

Hi,

Site works great, letsencrypt works perfect. I can't get 404 page to show and not sure why. Here's my server code:

server {
servername www. example.com;
return 301 $scheme:// example.com/$request
uri;
}

server {
listen 443 ssl;

server_name www. example.com  example.com;

ssl_certificate /etc/letsencrypt/live/ example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/ example.com/privkey.pem;


location / {
    proxy_pass http://localhost:3000;
    proxy_http_version 1.1;
    proxy_set_header upgrade $http_upgrade;
    proxy_set_header connection 'upgrade';
    proxy_set_header host $host;
    proxy_cache_bypass $http_upgrade;

  }

 location ~ /.well-known {
            allow all;
 }

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_dhparam /etc/ssl/certs/dhparam.pem;
    ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-$
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_stapling on;
    ssl_stapling_verify on;
    add_header Strict-Transport-Security max-age=15768000;

}

server {
listen 80;
servername example.com www. example.com;
return 301 https://$host$request
uri;

    error_page 404 /404.html;
    location = /404.html {
            root /usr/share/nginx/html;
            internal;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
            root /usr/share/nginx/html;
            internal;
    }

    location /testing {
            fastcgi_pass unix:/does/not/exist;
    }

}

404.html and 50x.html are in the correct location: /usr/share/nginx/html

Thank you!

1 Answer

With WordPress configured properly the 404 pages specified in your nginx configuration would never be displayed. WordPress has all requests for a file that does not physically exist go through index.php in order to handle custom permalink settings. For this reason, you should configure your 404 page within WordPress.

Have another answer? Share your knowledge.