404 page not working Nginx Ubuntu with letsencrypt installed

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


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

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_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

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

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

    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.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!