"configuration file /etc/nginx/nginx.conf test failed": How do I know why this happened?

sudo nginx -t should test all files and return errors and warnings locations


This particular commands worked for me. sudo apt-get remove --purge nginx nginx-full nginx-common

and sudo apt-get install nginx

credit to this answer on stackexchnage


The first solution is to test nginx conf using the basic

sudo nginx -t

Secondly, if you've changed the file yourself, copy/pasted json from one to another, there's a high chance that there's an encoding issue.

For example: " is not the same as

``

Try to write configurations by yourself. Check commas, colon and braces. Don't forget to reload the nginx.

sudo systemctl reload nginx

If you want to check syntax error for any nginx files, you can use the -c option.

[root@server ~]# sudo nginx -t -c /etc/nginx/my-server.conf
nginx: the configuration file /etc/nginx/my-server.conf syntax is ok
nginx: configuration file /etc/nginx/my-server.conf test is successful
[root@server ~]#