问题原文
原帖链接 · Ali · CC BY-SA 3.0
I have defined a custom error_log for a virtual server inside it's directory like so:
server {
listen 80;
server_name www.example.com;
root /home/www.example.com;
error_log /home/www.example.com/error.log;
}
this is my nginx.conf:
user nginx;
pid /run/nginx.pid;
worker_processes 1;
Nginx starts as root with it's commands with no problems:
nginx -t
nginx
But when I try to start it using systemctl it won't start and status shows this:
nginx: [emerg] open() "/home/www.example.com/error.log" failed (13: Permission denied)
This is my nginx.service :
[Unit]
Description=The nginx HTTP and reverse proxy server
After=syslog.target network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PIDFile=/run/nginx.pid
ExecStartPre=/usr/sbin/nginx -t
ExecStart=/usr/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
I have almost tried anything like changing the user:group of the web directory to nginx:nginx. Even if I remove the error_log it starts using systemctl but it can't access the web directory although it's running under the same user.
I can't figure out why nginx can't access that directory when it's started with systemctl while it has access when it's started directly.
I'm on centos 7.
已采纳解答
原帖链接 · Alfonso · CC BY-SA 4.0
SELinux is probably not allowing nginx to access the/home directory. Try changing the root to /var/www as a test. Also when you are starting up nginx run journalctl -x in a different session to see the error messages and post them here.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
