"configuration file /etc/nginx/nginx.conf test failed": How do I know why this happened?
Solution 1
sudo nginx -t
should test all files and return errors and warnings locations
Solution 2
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
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
If you want to check syntax error for any nginx files, you can use the -c option.
[[email protected] ~]# 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
[[email protected] ~]#
Related videos on Youtube

bernie2436
Updated on July 30, 2021Comments
-
bernie2436 about 1 year
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?
-
RickyA over 8 yearsDo you still have "default" in your "/etc/ngix/sites-enabled"?
-
bernie2436 over 8 years@RickyA do you mean the "default" file? Yes, I still have that file located in that directory. I moved that file and ran nginx -s reload and still see the same behavior from the server
-
Mohammad AbuShady over 8 yearsthe error mentions the file csv, check that file in sites-enabled
-
kaiser over 6 yearsAd
sudo service nginx restart
) Nginx has a CLI tool as well:nginx -s reload
to reload the config in case it changed. That's much faster.
-
-
aitchkhan over 5 yearsit is testing only one file i.e: /etc/nginx/nginx.conf but how can I test sites-enabled/default?
-
Mohammad AbuShady over 5 yearsit think it would test all, as long as they are included in the default file ( which I assume they are ? ), if you are not using the default config file path then try using
-c
flag, songinx -c /etc/nginx/sites-enabled/default -t
-
Günther Eberl almost 4 yearsCan confirm what @MohammadAbuShady said. Although the manpage for
-t
somewhat vaguely says Don't run, just test the configuration file. The nginx checks configuration for correct syntax and then tries to open files referred in configuration. the files are not just checked for existence but parsed. As expected the exit code is 1 if error found and 0 otherwise.