Technology

#How to Test Your Nginx Config File (and Why You Should) – CloudSavvy IT

“#How to Test Your Nginx Config File (and Why You Should) – CloudSavvy IT”

NGINX Logo
NGINX

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.

/usr/local/nginx/sbin/nginx -t

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.

If you liked the article, do not forget to share it with your friends. Follow us on Google News too, click on the star and choose us from your favorites.

For forums sites go to Forum.BuradaBiliyorum.Com

If you want to read more like this article, you can visit our Technology category.

Source

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button
Close

Please allow ads on our site

Please consider supporting us by disabling your ad blocker!