Nginx:在Ubuntu上,nginx的权限被拒绝。

90

我是新手系统管理员。在Ubuntu上安装nginx 通过puppet之后,我得到了以下输出:

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

[warn] 1898#0: the "user" directive makes sense only if the master process runs with super-user privileges, ignored in /etc/nginx/nginx.conf:1

[emerg] 1898#0: open() "/var/log/nginx/access.log" failed (13: Permission denied)

我该如何摆脱所有这些信息?
我不想直接使用命令行(chown / chmod),并且每次创建新服务器时重复此过程。因此,我正在考虑在puppet清单中添加什么。
在这种情况下,最好的系统管理员实践是要更改/var/log/nginx的所有者/权限还是将日志存储在不同位置?如果chown / chmod是正确的方法,那么哪些特定权限能够确保最高级别的安全性?
我尝试了这个,但没有帮助:
  file { '/var/log/nginx':
    ensure  => directory,
    mode    => '0755',
    owner   => 'www-data',
    group   => 'www-data',
    recurse => true
  }

编辑:

vagrant@precise64:~$ ps aux | grep [n]ginx
root      1001  0.0  0.1  62908  1388 ?        Ss   08:47   0:00 nginx: master process /usr/sbin/nginx
www-data  1002  0.0  0.1  63260  1696 ?        S    08:47   0:00 nginx: worker process
www-data  1003  0.0  0.1  63260  1696 ?        S    08:47   0:00 nginx: worker process
www-data  1004  0.0  0.1  63260  1696 ?        S    08:47   0:00 nginx: worker process
www-data  1005  0.0  0.1  63260  1696 ?        S    08:47   0:00 nginx: worker process

你确定木偶代码已经应用了吗(例如使用 vagrant provision)? /etc/nginx/nginx.conf 使用 www-data 还是 nginx 来运行非主进程的 nginx? - Terry Wang
检查已运行的端口,如果 Nginx 端口 44380 如果它们被其他进程使用,则可能会导致类似的错误。使用命令 sudo netstat -tulpn 检查端口 80 或 443 是否被其他进程使用。 - Akhil S
12个回答

-4

这对我有效,

sudo chmod -R 777 /var/log/nginx

-5

Nginx需要通过命令 'sudo /etc/init.d/nginx start' 运行


我无法让“sudo service nginx restart”正常工作,输出了以下内容:“service nginx restart Failed to restart nginx.service: The name org.freedesktop.PolicyKit1 was not provided by any .service files”,但是“sudo /etc/init.d/nginx restart”对我来说完美运行。 - mohnstrudel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接