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

Permission Error Running NGINX as User serving from User Directory

· 52CE 我爱测

Running: CentOS 7, NGINX 1.10.0 I am receiving a permission error when running NGINX as "user {username};" with the following folder structure and assigned permissions: /home/{username} drwxr-xr-x. 4 {username} {username} 88 Sep …

问题原文

原帖链接 · Ryan Prentiss · CC BY-SA 3.0

Running: CentOS 7, NGINX 1.10.0

I am receiving a permission error when running NGINX as "user {username};" with the following folder structure and assigned permissions:

/home/{username}

drwxr-xr-x. 4 {username} {username}  88 Sep 28 04:21 .
drwxr-xr-x. 4 {username} {username}  30 Sep 28 04:21 example.com

/home/{username}/example.com

drwxr-xr-x. 2 {username} {username}  6 Sep 28 07:15 logs --currently empty
drwxr-xr-x. 2 {username} {username}  6 Sep 28 04:21 public --currently empty

sudo nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

sudo systemctl status nginx

nginx.service - The nginx HTTP and reverse proxy server
  Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
  Active: failed (Result: exit-code) since Wed 2016-09-28 07:16:15 UTC; 17min ago
Process: 1520 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=1/FAILURE)
Process: 1519 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)

Starting The nginx HTTP and reverse proxy server...
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] open() "/home/{username}/example.com/logs/access.log" failed (13: Permission denied)
nginx: configuration file /etc/nginx/nginx.conf test failed
nginx.service: control process exited, code=exited status=1
Failed to start The nginx HTTP and reverse proxy server.
Unit nginx.service entered failed state.
nginx.service failed.

已采纳解答

原帖链接 · MikeA · CC BY-SA 3.0

# install semanage if you don't already have it:
yum install policycoreutils-python

# check if SELinux is running:
sestatus

# check output for:     Current mode: enforcing.



# give your content and logs directory a new default context.
semanage fcontext -a -t httpd_sys_rw_content_t "/home/{username}/public(/.*)?"
semanage fcontext -a -t httpd_log_t "/home/{username}/logs(/.*)?"

# apply the default context to the directory
restorecon -R /home/{username}

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

资料来源与适用范围

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

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

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