V
V
Valeriu1472017-02-25 09:53:46
PHP
Valeriu147, 2017-02-25 09:53:46

Why doesn't CHROOT work with php-fpm?

I have to chroot my ftp directory on the site. My config php-fpm.conf:

[mysite.com]
listen = /var/run/php7-fpm-chroot-filemanager.sock
chroot = /var/www/mysite.com/fileman
chdir = /
user = filemanuser
group = filemangroup
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

Part of the config in the virtual host, which is responsible for the ftp directory:
location ~* /fileman/(.+\.php)$
    {

            root /var/www/mysite.com/;
            include /etc/nginx/fastcgi_params;
            if (!-f /var/www/mysite.com$fastcgi_script_name) {
                    return 405;
            }
            fastcgi_index index.php;
            fastcgi_pass unix:/var/run/php7-fpm-chroot-filemanager.sock
            fastcgi_param SCRIPT_FILENAME /var/www/mysite.com$fastcgi_script_name;
    }

After restarting the php-fpm service, on the page, I see:
File not found.
In the nginx logs:
2017/02/24 20:12:22 [error] 18390#18390: *108 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.110.25, server: www.mysite.com, request: "GET /fileman/index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php7-fpm-chroot-filemanager.sock:", host: "www.mysite.com"

The very fact that everything works without CHROOT. Tell me what I'm doing wrong and where I have an error? For the second day I've been fighting and changing ways, I've tried different things.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry MiksIr, 2017-02-25
@miksir

chroot is a change of the root ("/") of the file system. PHP having switched to the new root knows nothing about the levels above, for it the root is now /var/www/mysite.com/fileman. Those. when you say - execute script fastcgi_param SCRIPT_FILENAME /var/www/mysite.com$fastcgi_script_name; - it searches from its new root, which means that it actually searches the file system for the file /var/www/mysite.com/fileman/var/www/mysite.com$fastcgi_script_name
If you don't understand why you are cheating, it's better not to use it. There may be many nuances.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question