以下是我的nginx配置文件 /etc/nginx/nginx.conf
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试图打开.
为什么它尝试访问另一个错误日志文件?
这已经很老了...但我经历了同样的痛苦,这是我的解决方案.
如您所见,日志是警报,而不是阻止错误:
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