高手来瞅瞅, centos 下, nginx 安装后,修改日志路径,造成无法启动

2017-03-23 23:29:03 +08:00
 colordog

高手们给看看啊,这个是报错内容

3 月 23 11:23:59 localhost.localdomain systemd[1]: Starting nginx - high performance web server...
3 月 23 11:23:59 localhost.localdomain nginx[30550]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
3 月 23 11:23:59 localhost.localdomain nginx[30550]: nginx: [emerg] open() "/home/www/log/error.log" failed (13: Permission denied)
3 月 23 11:23:59 localhost.localdomain nginx[30550]: nginx: configuration file /etc/nginx/nginx.conf test failed
3 月 23 11:23:59 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
3 月 23 11:23:59 localhost.localdomain systemd[1]: Failed to start nginx - high performance web server.
3 月 23 11:23:59 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
3 月 23 11:23:59 localhost.localdomain systemd[1]: nginx.service failed.

下面是 nginx.conf 文件内容

================== 配置文件==================== user apache;
worker_processes 1;

error_log /home/www/log/error.log warn;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" "$http_x_forwarded_for"';

access_log  /home/www/log/access.log  main;

sendfile        on;
#tcp_nopush     on;

keepalive_timeout  65;

gzip  on;

include /etc/nginx/conf.d/*.conf;

}

======================配置文件=========================

已知 /home/www/log 存在,并且属于 apche 用户名,用户组,为了测试权限,并且尝试给了 777 ,仍旧有问题

这个问题感觉装系统有时候会发生,有时候又没事,很奇怪, apache 也是,其他软件没遇到,感觉好奇怪。

10622 次点击
所在节点    NGINX
23 条回复
kmahyyg
2017-03-23 23:32:22 +08:00
换到 /var/log 下试试
colordog
2017-03-23 23:34:00 +08:00
@kmahyyg 那个默认目录没有问题,在阿里云 down 后,修改路径基本没问题,自己找个虚拟机,或者 pc 装的系统,十有八九都会出这个问题,而且安装方法都一样
zsz
2017-03-23 23:34:20 +08:00
一定是权限问题, 当前启动 nginx 的用户没有权限打开这个日志文件写入
colordog
2017-03-23 23:36:23 +08:00
@zsz 看报错应该是,这个 nginx 里面设置了 use apache 了,然后新建的 log 都改成这个用户和用户组了,而且专门设置了 777 属性,真不知道再怎么弄了
kmahyyg
2017-03-23 23:36:34 +08:00
检查 nginx 到底在用哪一个用户,我的到目前为 5 台 vps ,从未遇到这个问题。改目录到一个大家都可以写的目录并 chown www:www 可以解决
kmahyyg
2017-03-23 23:37:40 +08:00
另外,检查下你的 /etc/nginx/conf.d 下的配置有没有相关读写的东西
colordog
2017-03-23 23:38:00 +08:00
@zsz <br />
[root@localhost nginx]# ps aux |grep nginx<br />
root 30595 0.0 0.0 112664 972 pts/0 R+ 11:37 0:00 grep --color=auto nginx
colordog
2017-03-23 23:39:30 +08:00
@kmahyyg 看下上面的结果,我在阿里云的 8 台服务器也没这个问题, vultr 的 2 台也没有,只是从官方下载的,然后自己安装的,室友八九都有这个问题
colordog
2017-03-23 23:43:48 +08:00
-- Unit nginx.service has begun starting up.
3 月 23 11:40:36 localhost.localdomain nginx[30609]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
3 月 23 11:40:36 localhost.localdomain nginx[30609]: nginx: [emerg] open() "/home/www/log/error.log" failed (13: Permission denied)
3 月 23 11:40:36 localhost.localdomain nginx[30609]: nginx: configuration file /etc/nginx/nginx.conf test failed
3 月 23 11:40:36 localhost.localdomain systemd[1]: nginx.service: control process exited, code=exited status=1
3 月 23 11:40:36 localhost.localdomain systemd[1]: Failed to start nginx - high performance web server.
-- Subject: Unit nginx.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit nginx.service has failed.
--
-- The result is failed.
3 月 23 11:40:36 localhost.localdomain systemd[1]: Unit nginx.service entered failed state.
3 月 23 11:40:36 localhost.localdomain systemd[1]: nginx.service failed.
3 月 23 11:40:36 localhost.localdomain polkitd[3159]: Unregistered Authentication Agent for unix-process:30603:203289 (system bus name :1.32, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale zh_CN.UTF-8) (disconnected from bus)
zsz
2017-03-23 23:50:26 +08:00
@colordog 尝试 sudo -u apache touch /home/www/log/test.log 看看能不能创建,如果不能,你这个 apache 用户对这个目录都不一定有权限,修改成正确的权限
kmahyyg
2017-03-23 23:51:18 +08:00
@colordog 前面的这个只能说明你的 nginx 没有运行,具体的建议你除非是 nginx 作为 apache 代理前端,否则将 log 目录与网站根目录的权限设为同一 owner(or group),先 777 试试。
colordog
2017-03-23 23:51:53 +08:00
@zsz 可以创建,没有任何问题
colordog
2017-03-23 23:52:23 +08:00
@kmahyyg 777 已测试,无效
Phant0m
2017-03-23 23:54:43 +08:00
open() "/home/www/log/error.log" failed (13: Permission denied) 很明显是权限或者 selinux 的问题好吧
关闭 selinux ( setenforce 0 )
看看 apache 启动的用户是不是 apache
zsz
2017-03-23 23:56:48 +08:00
@colordog nginx 配置贴出来,你确认 nginx 使用的 apache 这个用户? 确认下 root 用户对这个目录有权限没
kmahyyg
2017-03-23 23:59:14 +08:00
@colordog

检查下你的系统有哪些用户 cat /etc/passwd ,检查 acl 配置

同时,将 nginx.conf 用这个写下试试:
(以下仅为示例)

root@supply:/usr/local/nginx/conf# cat ./nginx.conf

# user 你的用户组 你的用户名;
user www www;
worker_processes 1;

error_log /data/wwwlogs/error_nginx.log crit;
pid /var/run/nginx.pid;
worker_rlimit_nofile 51200;


ls -alh 列下 log 目录下的其他的 log 文件:

drwxr-xr-x 4 root root 4.0K Dec 15 21:45 ..
-rw-r--r-- 1 www root 0 Mar 23 06:25 access_nginx.log
colordog
2017-03-24 00:00:57 +08:00
@Phant0m 已经解决 关闭 selinux ( setenforce 0 ) 这个管用,能给讲讲不
colordog
2017-03-24 00:01:40 +08:00
@zsz 已经解决,不是配置文件问题, 14 楼的方法完美解决了,感谢
colordog
2017-03-24 00:01:55 +08:00
@kmahyyg 已经解决,不是配置文件问题, 14 楼的方法完美解决了,感谢
kmahyyg
2017-03-24 00:04:02 +08:00
很明显 selinux 和 acl 策略出问题了,没必要的话不建议关闭 selinux.

google 下 selinux 策略去找原因吧

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/349884

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX