在 apache 上运行的网站目录的最佳所有者/权限设置

Dan*_*yRe 4 permissions apache2

我在我的虚拟服务器上运行 Ubuntu,我已经设置了很多关于我的主题的设置。但我不确定它是否设置正确。

我目前的设置如下:

阿帕奇2:

export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
export APACHE_PID_FILE=/var/run/apache2.pid
Run Code Online (Sandbox Code Playgroud)

我阅读了有关添加额外用户的文章,例如sudo adduser apache运行 apache 服务器的用户,那么这是一个不错的选择吗?

网站目录:

drwxr-xr-x 5 www-data:www-data 4.0K Feb  5 04:16 mysite/
Run Code Online (Sandbox Code Playgroud)

例如,此目录位于/var/www. 我在目录中的文件夹设置是chmod 755,我的文件是644. 它应该归 www-data 还是我的用户名所有?

如果你能给我一些关于这方面的最佳实践,我会很高兴。谢谢你的建议!

小智 6

我学到的最重要的事情是不要给 Apache 写访问任何你不需要写的东西,例如缓存、用户或你可以上传东西的下载目录。

因此,拥有sudo chown user:user网站目录中的所有内容的所有权,并为o另一位授予所需的权限......

替换user:user为您想要的用户和组。

在目录上,您可以使用如下命令:

sudo chmod o+rx /var/www/'directory' #make directory read and executable for other
sudo chmod o-wx /var/www/'directory'/'files' #remove write and execute from files
sudo chmod o+r  /var/www/'directory'/'files' #add read to files
Run Code Online (Sandbox Code Playgroud)

您还可以使用一个find有点高级但使工作更容易的命令,例如(在拥有文件后):

chown user:user /var/www/ -R # this is only an example.. 
Run Code Online (Sandbox Code Playgroud)
  • 目录
sudo chmod o+rx /var/www/'directory' #make directory read and executable for other
sudo chmod o-wx /var/www/'directory'/'files' #remove write and execute from files
sudo chmod o+r  /var/www/'directory'/'files' #add read to files
Run Code Online (Sandbox Code Playgroud)
  • 档案
chown user:user /var/www/ -R # this is only an example.. 
Run Code Online (Sandbox Code Playgroud)

我试图尽可能地描述。如果需要,我可以解释更多。这谈论了大约一半的权限:

http://www.linuxforums.org/forum/servers/5270-apache-conf-html-permissions.html