If you’re making changes to your nginx configuration files, you are running a huge risk if you restart nginx and you made a mistake, a typo, or copied and pasted from Stackoverflow wrong. Luckily there’s an easy built-in way to test your configuration files to make sure they won’t break everything.
The worst part about making a mistake in your config files is that nginx will stop and it won’t start back up again until you fix the problem. So anybody trying to visit your site will get a fun error page.
So first you’ll want to figure out where nginx is located, which you can always do with a quick
ps -ef | grep nginx (or many other methods that produce similar output).
So now that we know where the binary is located, just simply run it with the -t argument.
If you made a mistake, you’ll get an error message that indicates it failed.
If it succeeded, you’ll get a message that everything is fine.
So now that you know your syntax is correct, you can restart nginx (gracefully) by using service nginx reload. Or… you could chain them together so the reload happens but only if the syntax was correct, using the && operator like this:
/usr/local/nginx/sbin/nginx -t && /usr/local/nginx/sbin/nginx -s reload
It’s worth noting that your nginx might be located in a different folder, so you should adjust the path accordingly.
- › T-Mobile Is Selling Your App Activity: Here’s How to Opt Out
- › A World Without Wires: 25 Years of Wi-Fi
- › What’s New in Windows 11’s 22H2 Update: Top 10 New Features
- › What Are the Best Nintendo Switch Games in 2022?
- › How Much Does It Cost to Operate an Electric Lawn Mower?
- › NZXT Signal 4K30 Capture Card Review: Lossless High-Quality Footage