Nginx Configuration Testing


After some time when dealing with web servers you’ll probably end up messing with nginx configurations which can lead to, at some point, an error being thrown when you try to reload the service…and nginx isn’t known for throwing the most communicative errors… So how do we know what happened?

First we’ll track down the see where abouts in the restart did the service fail, we can find out by running:

sudo systemctl status nginx

This will give you an idea. Now inside the lines that showed if you see something like:

nginx: configuration file /etc/nginx/nginx.conf test failed

then you know it is a configuration issue that has caused it to fail to restart(or even start depending). So how do we check what we did wrong? Easy!

sudo nginx -c /etc/nginx/nginx.conf -t

This will let nginx know that the config “-c” that youre trying to use “/etc/nginx/nginx.conf” needs “-t” testing.

1. nginx: [emerg] unknown directive "serer_name" in /etc/nginx/sites-enabled/default:6
2. nginx: configuration file /etc/nginx/nginx.conf test failed

This would indicate there is an error, this case a typo as serer_name should be server_name, on line 6 that is causing it to fail to start. So now you have an error that you can actually deal with and sort to fix. Hope this helps!