Reputation: 23921
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?
Upvotes: 124
Views: 241743
Reputation: 3748
One reason could be the fact that the path /var/log/nginx/
does not exist. In my case someone deleted part of that path and /var/log/nginx/error.log
was not able to populate . When I restored the path, I was able to get all tests cleared (checked with sudo nginx -t -c /etc/nginx/nginx.conf
) and start nginx again.
Upvotes: 0
Reputation: 2731
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
Upvotes: 6
Reputation: 198
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 ~]#
Upvotes: 3
Reputation: 1126
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
Upvotes: 30
Reputation: 42899
sudo nginx -t
should test all files and return errors and warnings locations
Upvotes: 214