Apache + PHP-FPM + chroot结果“文件未find”错误

我想使用PHP-FPM池的chroot属性将chroot设置为DocumentRoot。 使用下面的设置,无论我做什么,我只得到一个“文件未find”。 错误:

/etc/php5/fpm/pool.d/example.conf

[example] user = example group = example listen = /var/run/php_fpm_example.sock pm = dynamic pm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 chroot = /opt/jail/example/home/example php_admin_value[open_basedir]=/opt/jail/example/home/example 

在/ etc / apache2的/启用的站点 – /例子

 <VirtualHost *:80> ServerName example.domain.name ServerAlias www.example.domain.name DocumentRoot /opt/jail/example/home/example <Directory /opt/jail/example/home/example> AllowOverride All Order Allow,Deny Allow from all </Directory> <IfModule mod_fastcgi.c> <FilesMatch \.php$> SetHandler php-script </FilesMatch> Action php-script /php5-fpm-handler Alias /php5-fpm-handler /vhost_example FastCGIExternalServer /vhost_example -socket /var/run/php_fpm_example.sock </IfModule> </VirtualHost> 

所以网站本身位于/ opt / jail / example / home / example。 你可能会觉得很奇怪,但并不重要,这是由jailkit引起的。

谢谢你的帮助。

PHP在chroot监狱里面运行。 所以一旦你设置这个:

 chroot = /opt/jail/example/home/example 

然后path/opt/jail/example/home/example成为PHP的path。 因为这是不合情理的:

 php_admin_value[open_basedir]=/opt/jail/example/home/example 

因为PHP不再有权访问/ opt / jail / example ….因为它在根path之外。

你还没有发布它,但你也需要改变fastcgi_paramconfiguration文件,在那里你设置SCRIPT_FILENAME参数,可能看起来像这样:

 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 

需要将其改为如下所示:

 fastcgi_param SCRIPT_FILENAME webroot/$fastcgi_script_name; 

如果将chroot + webroot + $fastcgi_script_name的值组合在一起,则可以获得磁盘上文件的绝对path。 由于PHP在chroot中运行,因此不需要将其包含在path中。

顺便说一句,将chroot设置为高于webroot的一个级别是一个更好的做法,这样您的应用程序就可以将日志文件写入到chroot中,而不是在webroot中,这样他们就不会意外地由用户下载。

所以你的目录是:

 /opt/jail/example/home/ <-- chroot /opt/jail/example/home/example <-- Read only directory is exposed as webroot (or document root). /opt/jail/example/home/var/log <-- Writeable directory that holds log files.