大网数据广告活动
服务器运维问答

How to dismiss nginx warning message nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)

· 52CE 我爱测

I'm running nginx using common user not root. I have nginx installed system-wide, but have nginx.conf in HOME. $HOME/nginx/nginx.conf worker_processes 1; error_log /home/worker/nginx/log/nginx/error.log warn; pid /home/worker/ngi…

问题原文

原帖链接 · gacopu · CC BY-SA 4.0

I'm running nginx using common user not root. I have nginx installed system-wide, but have nginx.conf in HOME.

$HOME/nginx/nginx.conf

worker_processes  1;
error_log  /home/worker/nginx/log/nginx/error.log warn;
pid        /home/worker/nginx/run/nginx.pid;
events {
  worker_connections  1024;
}
http {
  include      /etc/nginx/mime.types;
  default_type application/octet-stream;
  access_log   /home/worker/nginx/log/nginx/access.log;
  server {
    listen 8080;
    root /home/worker/nginx/data;
  }
}

start nginx

$ nginx -c /home/worker/nginx/nginx.conf
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)

As you can see in the nginx.conf, I have defined error_log, but I still got the warning message:

nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (13: Permission denied)

nginx itself works, just want to remove this warning message, how can I do that?

社区高分解答

原帖链接 · Vincent Stragier · CC BY-SA 4.0

I'm late to the party, but I've had this issue for another reason. I simply added the access rights to the folder and files for nginx (www-data user in my case):

sudo chown -R www-data:www-data /var/log/nginx

I've actually removed the whole folder and log file and recreated them:

sudo rm -rf /var/log/nginx
sudo mkdir /var/log/nginx
sudo touch /var/log/nginx/error.log
sudo chown -R www-data:www-data /var/log/nginx

Maybe there is a more elegant solution.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-05-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。