404 page not working Nginx Ubuntu with letsencrypt installed


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

server { server_name www.; return 301 $scheme://$request_uri; }

server { listen 443 ssl;

server_name www.;

ssl_certificate /etc/letsencrypt/live/;
ssl_certificate_key /etc/letsencrypt/live/;

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; server_name www.; return 301 https://$host$request_uri;

    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!

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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.