Question

Custom 404 not working in my nginx droplet, please help?

  • Posted on October 25, 2019
  • Nginx
  • CybilAsked by C K

I’m am new in nginx and before I user apache web server. So I got to know that .htaccess does not works in nginx, after doing some research I got to know about nginx.conf. When I added the 404 code in http inside server tree and reloaded nothing happens and the default 404 page is returned.

error_page 404 /404.html;
location  /404.html {
  internal;
}

I even tried doing this in my /etc/nginx/sites-available/default conf, but still no luck, however Im confused where should I put the code, in sites default conf or in the global nginx conf. Can some one please give me brief on this topic! Appreciate your help


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.

baraboom
DigitalOcean Employee
DigitalOcean Employee badge
October 25, 2019
Accepted Answer

Hi,

Not sure if you saw this tutorial during your research:

https://www.digitalocean.com/community/tutorials/how-to-configure-nginx-to-use-custom-error-pages-on-ubuntu-14-04

It’s a little older but I think it covers the main points, namely where to place the 404.html file itself and where in the config it goes (default), inside the server {} section and how to make the new config active.

If that doesn’t help, please paste more of your config and the location of your 404.html - good luck and let us know how it goes.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.