In case you’re making modifications to your nginx configuration recordsdata, you might be operating an enormous danger if you happen to restart nginx and also you made a mistake, a typo, or copied and pasted from Stackoverflow flawed. Fortunately there’s a straightforward built-in solution to check your configuration recordsdata to ensure they received’t break every part.
The worst half about making a mistake in your config recordsdata is that nginx will cease and it received’t begin again up once more till you repair the issue. So anyone attempting to go to your website will get a enjoyable error web page.
So first you’ll wish to work out the place nginx is positioned, which you’ll all the time do with a fast
ps -ef | grep nginx (or many different strategies that produce comparable output).
So now that we all know the place the binary is positioned, simply merely run it with the -t argument.
In case you made a mistake, you’ll get an error message that signifies it failed.
If it succeeded, you’ll get a message that every part is ok.
So now that you realize your syntax is appropriate, you’ll be able to restart nginx (gracefully) by utilizing service nginx reload. Or… you can chain them collectively so the reload occurs however provided that the syntax was appropriate, utilizing the && operator like this:
/usr/native/nginx/sbin/nginx -t && /usr/native/nginx/sbin/nginx -s reload
It’s price noting that your nginx could be positioned in a distinct folder, so you must alter the trail accordingly.