chroot php-fpm过程到用户家中

我正在将单个服务器上的每个网站从一个PHP实例中移出(所有网站中的所有文件都由apache拥有,并且只安装了默认的php库,而没有安装php-fpm) …我正在为每个单独的网站安装一个php-fpm池。

更好的安全性和网站的分离是我的目标,最大的目标是1个网站中的PHP脚本将无法从另一个网站访问PHP脚本。

我显然做错了什么。

我的环境:

  • CentOS 7
  • PHP 5.4.16
  • Apache 2.4.6

下面是一个php-fpm池configuration文件的示例:

[root@host]# cat /etc/php-fpm.d/website1.com.conf [website1.com] user = user1 group = user1 listen = /var/run/php-fpm/website1.com.sock listen.owner = user1 listen.group = user1 php_admin_value[disable_functions] = exec,passthru,shell_exec,system php_admin_flag[allow_url_fopen] = on php_admin_value[short_open_tag] = On pm = ondemand pm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 chdir = /home/www/website1.com/ 

这里是Apache的相应的vhost文件:

 [root@host]# cat /etc/httpd/conf.d/website1.com.conf <VirtualHost *:80> ServerAdmin [email protected] ServerName website1.com ServerAlias www.website1.com DocumentRoot /home/www/website1.com/www <Directory "/home/www/website1.com/www"> Options Includes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> ErrorLog /home/www/website1.com/logs/errors CustomLog /home/www/website1.com/logs/access_log common <FilesMatch "\.php$"> SetHandler "proxy:unix:///var/run/php-fpm/website1.com.sock|fcgi://website1.com/" </FilesMatch> </VirtualHost> 

所有文件和文件夹都由user1(该组也被设置为user1)。

我有一个PHP的脚本里面的“网站2”,仍然能够访问“网站1”的内容。 “网站2”的php-fpm池configuration文件中的设置以及“网站2”Apache vhostconfiguration文件中的设置与网站1相同(除了不同的文件夹path,主目录,chroot等)。

这是我的testing脚本,位于/ home / www / website2 / www /,可通过website2.com域名访问:

 <?php $test = file_get_contents('/home/www/website1.com/www/wp-config.php'); echo $test; #$files = scandir('/home/www'); #print_r($files); ?> 

然而,这个脚本的输出有点意外。 我没有看到wp-config.php的全部内容。 相反,我所看到的是文件中某个点以外的所有东西(如果您熟悉wp-config.php,我会看到define('SECURE_AUTH_KEY','foo')条目之后的所有内容)。

为什么这个在“user2”下运行的testing脚本访问并回显了“user1”目录下的wp-config.php的一些内容? 我认为chdir = /home/www/website1.com/指令会阻止这种事情。

看来你已经在你的php-fpm池configuration中设置了chdir而不是chroot了。

chdir指令简单地改变了该池的php进程的工作目录; 它不会启动chroot中的进程。

看到这个问题。