“配置文件/etc/nginx/nginx.conf 测试失败”: 我如何知道为什么会发生这种情况?

我是一个在 nginx 1.1.19和 ubuntu 12.04上尝试这个 这个教程的 nginx 菜鸟。我有 这个 nginx 配置文件。

当我运行这个命令时,测试失败了:

$ 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

我如何知道 nginx.conf 测试失败的原因?

184284 次浏览

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

Show file and track error

 systemctl status nginx.service

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

sudo apt-get install nginx

credit to this answer on stackexchnage

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 ~]#

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