How to Fix 404 Nginx Errors After Upgrading Ubuntu Server

One of the most common Web server combinations today features the Nginx Web server software implementation running on Ubuntu Server edition. This system is extremely efficient and easy to keep updated, since both packages continue to receive regular updates. System administrators generally install updates through the apt package manager, because Ubuntu Server has no graphical interface by default.

Ubuntu Server upgrades can sometimes generate unusual errors, and this lack of a graphical user interface can make it difficult for beginners to troubleshoot them. A few simple commands might be all it takes to fix 404 Nginx errors after an Ubuntu upgrade.

Method 1: Fixing Missing Nginx Error Pages

If a site is hosted on AWS, a private server or any other server configuration in a LEMP stack, it might go down randomly after an Ubuntu Server upgrade. Attempt to access the site from a Web browser, perhaps on another machine. Assuming it returns a 404 error, head to the Ubuntu Server CLI and run the command tail -f   to view all the most recent errors.

Should the log contain an error such as:

Your system is suffering from a missing error page. You might also see 40x.html in this line, though that’s relatively uncommon if your site is down and you’re getting 404 errors in exchange. Use the command ls   to see if there’s anything there. If not, then you’ll need to create the HTML code for a page for 50X errors.

Keep in mind that using the default  directory structure is often a problem with package managers, which can overwrite whatever gets stored there. You can change the docroot line in the Nginx configuration to prevent this sort of problem if you’re permitted to create a custom directory structure.

Method 2: Making PHP Find the Right Socket

You might also find an error that reads something like this in the

This means you have PHP7.0 running, but it isn’t running where it should be. The version number might be different depending on how you have PHP configured. Default installations will run from  or , but if you have this error that’s more than likely not the case.

Run the commands  and then find -name ‘php*fpm.sock’ to see if there’s a socket running somewhere on your system.

Assuming you received positive output, then you need to update your Nginx configuration to show the correct place in   the socket should be running. Naturally, /directoryPath would be replaced with the correct path. The line php/php7.0-fpm.sock should update the configuration if you’re using a socket file.

Users of the older TCP sockets that don’t use socket files can check if a PHP socket is currently listening to port 9000 by running sudo netstat -tulpn | grep 9000  off the command line. If this is the case, then open up your fastcgi_pass in nano, vi or another text editor and change out the unix:… line to instead use 127.0.0.1:9000 to update the socket.

Should none of this work, then make sure that php7.0-fpm or whatever version number you’re using is running with the command sudo systemctl restart php7.0-fpm, followed by repeating the above process.

Keep in mind that in most circumstances the listen entry in  and the value in need to be the same. You might try  for newer configurations, or 127.0.0.1:9000 for old style ones.

ABOUT THE AUTHOR

Kevin Arrows


Kevin Arrows is a highly experienced and knowledgeable technology specialist with over a decade of industry experience. He holds a Microsoft Certified Technology Specialist (MCTS) certification and has a deep passion for staying up-to-date on the latest tech developments. Kevin has written extensively on a wide range of tech-related topics, showcasing his expertise and knowledge in areas such as software development, cybersecurity, and cloud computing. His contributions to the tech field have been widely recognized and respected by his peers, and he is highly regarded for his ability to explain complex technical concepts in a clear and concise manner.