5

我注意到当我使用 测试我的 nginx 配置时nginx -t,它给了我一个警告:

nginx: [alert] could not open error log file: open() "/var/logs/nginx/error.log" failed (2: No such file or directory)

这是有道理的,因为 nginx 的日志路径实际上设置为/var/log/nginx/not /var/logs/nginx

我扫描了整个 nginx 配置目录,没有任何引用 /var/logs 的内容。我不知道这个日志位置可以写在哪里?

4

3 回答 3

11

在终端中运行此命令(注意:大写 V):

nginx -V

你在那里找到 /var/logs 吗?您的 nginx 可能会使用该默认文件位置进行编译。

[编辑]

我猜您的某些服务器块没有“error_log”指令。所以 nginx 会为他们尝试默认的。请注意,默认情况下,error_log 始终处于打开状态。

要解决此问题,您可以在主块(顶级)上添加此行,以便所有子块都可以继承该设置:

error_log /var/log/nginx/error.log;
于 2013-03-28T01:38:33.240 回答
4

您可以创建这些丢失的文件:

cd /var/log/nginx/
sudo touch error.log
sudo touch access.log
sudo chmod 750 *.log

然后触发nginx服务:

sudo systemctl daemon-relod
sudo service nginx restart 

[注意]:

您还可以禁用nginx日志记录:

于 2018-05-29T06:15:48.113 回答
2

你有一个错误的编译默认值。加载配置之前 nginx 注意到的任何内容都会转到编译时定义的错误日志的路径。如果不能,使用健全的路径或符号链接日志重新编译 nginx 到日志。

于 2013-03-29T07:42:03.550 回答