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:
It’s worth noting that your nginx might be located in a different folder, so you should adjust the path accordingly.