> CentOS > CentOS故障 >

centos7 nginx 配置日志,提示 No such file or directory

centos7+nginx1.6.2,配置目录/home/mysite绑定了100个网站(网站程序一样,链接数据库不一样)
然后他们的日志配置是

access_log /home/mysite/logs/$host/access.log main;


重新启动nginx,访问网站,访问日志没有生成,nginx错误日志中提示:

2014/12/22 23:56:11 [crit] 14021#0: *1 open() "/home/mysite/logs/xxxxA.com/access.log" failed (2: No such file or directory) while logging request, client$


修改nginx.conf

access_log /home/mysite/logs/$host.access.log main;


重启nginx再访问网站,错误日志:

2014/12/23 00:00:34 [crit] 14021#0: *6 open() "/home/mysite/logs/xxxxA.com.access.log" failed (13: Permission denied) while logging request, client: 113.$


目录 ll /home/mysite

[root@flxx nginx]# ll /home/mysite
total 12
drwxr-xr-x 2 mysite root 4096 Dec 22 23:04 bak
drwxr-xr-x 2 mysite root 4096 Dec 22 23:04 logs
drwxr-xr-x 2 mysite root 4096 Dec 22 23:37 www


如何解决

1)nginx 不同域名自动生成目录问题
2)nginx 日志写入权限问题

目录权限的问题,你的logs目录是除了root用户意外都不能写,所以会Permission denied,chown成Nginx的用户或者最简单权限改成777

(责任编辑:IT)