2019年1月17日更新,我们下面来介绍nginx配置文件的错误
如果你编辑了一些nginx配置文件,而nginx不希望重新加载或重启,例如出现如下错误信息:
1 2 3 | # service nginx reload Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. |
您的配置文件中可能有一些错误。
有一个简单的命令来检查错误(您需要以根用户身份运行它):nginx -t
示例输出:
1 2 | nginx: [emerg] unknown directive "autoindex$" in /etc/nginx/sites-enabled/mysite:31 nginx: configuration file /etc/nginx/nginx.conf test failed |
首先,最后一行告诉您配置文件中确实存在一些错误。
第一行告诉您它的确切位置:/etc/nginx/sites-enabled/mysite:31意味着:查看文件/etc/nginx/sites-enabled/mysite,第31行。
在这种情况下,实际的错误消息是未知的指令“autoindex$”。通过检查上述文件,我发现我不小心输入了autoindex $;而不是自动索引;
修复这个问题后,nginx -t显示配置文件现在看起来是正确的:
1 2 | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful |
请注意,虽然大多数nginx无法(重新)启动的情况是由配置文件中的问题引起的,但是在某些情况下,配置文件似乎是正确的,nginx仍然不会启动。在这种情况下。查看通常位于/var/log/nginx/error的日志文件。日志。要查看它,您需要是root用户。我推荐这个命令:
1 | sudo tail -n 1000 /var/log/nginx/error.log |