"configuration file /etc/nginx/nginx.conf test failed": How do I know why this happened?
NginxNginx Problem Overview
I'm an nginx noob trying out this this tutorial on nginx 1.1.19 on ubuntu 12.04. I have this nginx config file.
When I run this command the test fails:
$ sudo service nginx restart
Restarting nginx: nginx: [crit] pread() "/etc/nginx/sites-enabled/csv" failed (21: Is a directory)
nginx: configuration file /etc/nginx/nginx.conf test failed
How do I know why the nginx.conf test failed?
Nginx Solutions
Solution 1 - Nginx
sudo nginx -t
should test all files and return errors and warnings locations
Solution 2 - Nginx
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
Solution 3 - Nginx
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
Solution 4 - 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 ~]#
Solution 5 - Nginx
Show file and track error
systemctl status nginx.service