apt-get 安装 nginx 时文件仍归 root 所有

apt-get 安装 nginx 时文件仍归 root 所有

这最初发布在 stackoverflow 上,但建议我将其发布在这里: https://stackoverflow.com/questions/23274818/apt-get-installation-of-nginx-leaves-files-owned-by-root/23346149

在使用 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

主进程也归 root 所有,尽管有以 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 文件和文件夹的所有权以确保系统安全。

答案1

应该是这样的。工作进程仍然可以它所需的文件,但是除非您有一个应用程序特别需要此选项,否则它永远不需要写入文件。

答案2

“在 Apache 中,为了确保安全,我们始终强调确保文件和进程不由 root 所有。”

这不完全正确。对于 Apache 和 nginx

  • 主进程将以 root 身份运行,工作进程将以其他用户身份运行
  • 工作进程应该有权限读取它们所服务的内容,但无权写入

相关内容