linux - nginx 的 apt-get 安装留下 root 拥有的文件

标签 linux apache nginx system-administration ownership

在使用 apache httpd 多年后,我将转向 nginx。我使用 apt-get 安装 nginx 服务器并注意到所有文件都归 root 所有。

debian@nginx-explore:~$ ls -la /usr/share/nginx/www/
total 16
drwxr-xr-x 2 root root 4096 Apr 23 21:09 .
drwxr-xr-x 3 root root 4096 Apr 23 21:09 ..
-rw-r--r-- 1 root root  383 Jul  7  2006 50x.html
-rw-r--r-- 1 root root  151 Oct  4  2004 index.html

master 进程也归 root 所有,尽管有 worker 进程以 www-data 运行

debian@nginx-explore:~$ ps aux|grep nginx
root      2724  0.0  0.1  62348  1324 ?        Ss   Apr23   0:00 nginx: master process /usr/sbin/nginx
www-data  2725  0.0  0.1  62688  1624 ?        S    Apr23   0:03 nginx: worker process
www-data  2726  0.0  0.1  62688  1624 ?        S    Apr23   0:03 nginx: worker process
www-data  2727  0.0  0.1  62688  1624 ?        S    Apr23   0:03 nginx: worker process
www-data  2728  0.0  0.2  62688  2132 ?        S    Apr23   0:00 nginx: worker process

在 Apache 中,作为一项安全措施,始终强调确保文件和进程不归 root 所有。在使用 nginx 时这不是什么大问题有什么原因吗?

最终我需要知道我是否应该调整 nginx 文件和文件夹的所有权以确保我的系统安全。

最佳答案

由于文件归 root 所有,负责处理网络流量的 nginx 用户 (www-data) 无法通过安全漏洞或以其他方式允许对 www 文件进行写访问。因此,它遵循 principle of least privilege .

从另一方面来看,如果你将文件更改为 nginx 用户(www-data)拥有,那么就有可能利用 nginx worker 进程修改它拥有的文件,在这个保护您的 www 页面。

关于linux - nginx 的 apt-get 安装留下 root 拥有的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23274818/

相关文章:

python - flask + Apache (mod_wsgi) + boto3 : name 'ssl' is not defined

php - XAMPP 不解释 PHP 代码 + 错误

nginx - 如何在 nginx 服务器上干净地处理 letsencrypt 的第一次使用?

c++ - 图形界面认证

c - 为什么 readdir() 将 ".."列为文件之一?

linux - 我们如何按照特定模式从文件中的行中删除字符串?

从 Ubuntu 到 Red Hat 的 Linux Python Dogtail 更新 - pyatspi 库

Apache .htaccess 隐藏 .php 和 .html 扩展名

nginx - 如何使用 ingress nginx 负载平衡套接字

docker 通过 https 提供内容而没有域(仅具有公共(public) IP 地址)