bernie2436
bernie2436

Reputation: 23921

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

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

Answers (6)

pebox11
pebox11

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

Mujeeb Ishaque
Mujeeb Ishaque

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

Sreeraj Karichery
Sreeraj Karichery

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

Eric
Eric

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

GusTavo Moreno
GusTavo Moreno

Reputation: 17

Show file and track error

 systemctl status nginx.service

Upvotes: -1

Mohammad AbuShady
Mohammad AbuShady

Reputation: 42899

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

Upvotes: 214

Related Questions