首先为网站内容目录设置权限:
| 12
 3
 4
 5
 6
 7
 
 | usermod -a -G www-data operatorchown -R www-data:www-data /var/html/htdocs
 chmod -R o-x /var/html/htdocs
 chmod /var/html/htdocs -type d -exec chmod g+s {} \;
 setfacl -d -R -m u::rwx /var/html/htdocs
 setfacl -d -R -m g::rwx /var/html/htdocs
 setfacl -d -R -m o::--- /var/html/htdocs
 
 | 
将 operator 加入 www-data 组使其有权限部署网站内容。
设置组的 setgid 标志位,可以确保子文件夹写入或修改后,依然属于 www-data 组。值得注意的是,Linux 会忽略文件夹的 setuid 标志位。
最后用 ACL 修改 umask。使用 ACL 修改的原因是,ACL 对 umask 的修改可以持久化。
同理,为 Nginx 配置目录设置权限:
| 12
 3
 4
 5
 6
 7
 8
 
 | useradd  webmasterusermod -a -G webmaster operator
 chown -R webmaster:webmaster /etc/nginx/sites
 chmod -R o-x /etc/nginx/sites
 chmod /etc/nginx/sites -type d -exec chmod g+s {} \;
 setfacl -d -R -m u::rwx /var/html/htdocs
 setfacl -d -R -m g::rwx /var/html/htdocs
 setfacl -d -R -m o::--- /var/html/htdocs
 
 | 
最后,允许 webmaster 通过 sudo 重启 Nginx:
| 1
 | echo "%webmaster ALL= NOPASSWD: /usr/bin/systemctl restart nginx" >> /etc/sudoers
 |