我正在使用 Apache 虚拟主机和 suEXEC(Centos 6.5、Apache 2.2.5 和 PHP 5.3.3)配置多域 Web 服务器。
我想阻止 PHP 访问网站目录上方的文件夹/文件。我将逐步解释我的设置是什么,最后是什么问题。
这是我正在使用的文件夹结构:
/var/www/domain.com/public_html/
在 /var/www/ 我有这个:
drwxr-xr-x 2 root root 4.0K Aug 13 13:30 cgi-bin/
drwxrwxr-x 4 apache apache 4.0K Jan 28 09:16 site1.com/
drwxrwxr-x 4 apache apache 4.0K Jan 28 08:44 site2.com/
drwxr-xr-x 4 apache apache 4.0K Jan 30 11:08 site3.com/
在 /var/www/site1.com/ 里面:
drwxr-xr-x 2 apache apache 4.0K Jan 30 10:16 logs/
drwxr-xr-x 3 user1 user1 4.0K Jan 30 11:08 public_html/
httpd.conf 中 site1.com 的虚拟主机定义为:
<VirtualHost *:80>
ServerAdmin info@site1.com
DocumentRoot /var/www/site1.com/public_html
ServerName www.site1.com
ServerAlias site1.com
ErrorLog /var/www/site1.com/logs/error_log
CustomLog /var/www/site1.com/logs/access_log common
php_flag log_errors on
php_flag display_errors on
php_value error_log /var/www/site1.com/logs/php_errors.log
<Directory "/var/www/site1.com/public_html">
Options FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
SuexecUserGroup user1 user1
AddHandler application/x-httpd-php .php
Action application/x-httpd-php /cgi-bin/php-cgi
ScriptAlias /cgi-bin/ /var/www/site1.com/public_html/cgi-bin/
<Directory "/var/www/site1.com/public_html/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
但是,我编写并执行了这个 php 脚本 (www.site1.com/test.php)
<?php
system("id");
print "<pre>";
system("ls /var/www");
print "</pre>";
?>
我得到:
uid=503(user1) gid=503(user1) groups=503(user1)
site1.com
site2.com
site3.com
这意味着 PHP 可以访问我服务器中的任何文件夹(包括 /etc /var /usr 等)
我想阻止 Apache/PHP 访问 /var/www/site1.com 上面的所有文件夹
我应该如何配置 Apache?
我已经对这个问题进行了广泛的谷歌研究,但我找不到解决方案。
非常感谢。