如何更改 nginx 临时文件和日志文件夹或完全禁用日志记录

如何更改 nginx 临时文件和日志文件夹或完全禁用日志记录

我在 Windows 7 下运行 nginx 1.3.5,我需要直接从只读媒体(CD 或 DVD)执行 nginx,但是当我想要运行它时,它会失败并出现以下错误:

nginx: [alert] could not open error log file: CreateFile() "logs/error.log" fail
ed (5: Access is denied)
2012/08/28 13:52:46 [emerg] 5604#2864: CreateDirectory() "J:\nginx-1.3.5/temp/client_body_temp" failed (5: Access is denied)

其中 J 是我的 CD-ROM 驱动器号。
我已将 nginx.conf 更改为完全禁用日志记录,但似乎它仍然试图在启动时在“/logs”文件夹中创建一个名为“error.log”的文件并在“/temp”文件夹中创建一些额外的临时内容,所以我想将“logs”和“temp”目录路径更改为 Windows 临时文件夹 (%temp%),但我不知道该怎么做。
另外我想知道为什么在禁用错误日志记录后 nginx 仍然创建“logs/error.log”?

答案1

http://nginx.org/en/docs/http/ngx_http_log_module.html列出了控制日志记录的指令,具体来说有以下两个指令:

syntax:     access_log path [format [buffer=size]]; 
            access_log off;
default:    access_log logs/access.log combined;
context:    http, server, location, if in location, limit_except

syntax:     error_log file | stderr [debug | info | notice | warn | error | crit | alert | emerg];
default:    error_log logs/error.log error;
context:    main, http, server, location 

因此,虽然您可以完全禁用 access_log,但对于 error_log 似乎却不行。不过,您仍然可以通过在 nginx 配置中添加以下内容来实现所需的效果;

error_log /dev/null emerg; #redirect the logging we can't shut off to a black hole;
acces_log off; #disable acces log

更新:刚刚注意到 windows 标签,请参阅这个问题对于 Windows 上的 /dev/null 等效项

答案2

据我所知,您可以禁用访问日志,但不能禁用错误日志。Nginx 正在尝试将消息创建/写入位于 CD/DVD 上的日志文件。尝试将日志目录设置为 HD 分区,例如 C: 或 D:

相关内容