下面是位于/etc/nginx/nginx.conf
中的nginx配置文件
user Foo;
worker_processes 1;
error_log /home/Foo/log/nginx/error.log;
pid /home/Foo/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
}
http {
access_log /home/Foo/log/nginx/access.log;
server {
listen 80;
location = / {
proxy_pass http://192.168.0.16:9999;
}
}
}
如您所见,我将日志、pid文件位置更改为主目录。
当我重新启动Linux
时,Nginx
会在我设置的文件和pid文件中记录错误日志。
但是,当尝试nginx -s reload
或其他错误日志文件时,它尝试打开其他错误日志文件。
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
2015/12/14 11:23:54 [warn] 3356#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
2015/12/14 11:23:54 [emerg] 3356#0: open() "/home/Foo/run/nginx.pid" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed
我知道,我可以用sudo
解决权限错误,但是这里的主要问题是一个错误日志文件(/var/log/nginx/error.log
) Nginx试图打开。
为什么它试图访问另一个错误日志文件?
发布于 2015-12-14 02:34:49
检查/home/Foo/log/nginx/目录的权限。它必须由nginx写。设置权限如下:
sudo chmod 766 /home/Foo/log/nginx
发布于 2018-11-26 07:37:22
你可能需要用sudo
来启动它
sudo nginx -t
发布于 2016-08-24 13:22:38
这是旧的..。但我经历了同样的痛苦,这是我的解决办法。
如您所见,日志是一个警报,而不是阻塞错误:
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)
这不应该是个问题:) Nginx只是喜欢在启动时检查该文件.
只需使用-p
选项即可。像这样在本地发布Nginx的东西对我来说很管用:
nginx -c /etc/nginx/nginx.conf -g 'daemon off;' -p /home/Foo/log/nginx
https://stackoverflow.com/questions/34258894
复制相似问题