我应该在我的网站上使用 chroot 作为我的 ftp 目录:我的 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
我的 nginx.conf 部分:
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;
}
重新启动服务后,我在页面上看到:
File not found.
在nginx的日志中:
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"
没有 chroot 选项,一切都正常。我哪里出错了?请帮忙。
答案1
和文件未找到和主要脚本未知,查看SCRIPT_FILENAME
变量。
该变量将脚本的路径名传递给php-fpm
。在php-fpm
chrooted 环境中运行时,路径名必须相对于 chroot 目录。
您已经使用指令中的正则表达式捕获了大部分修改后的路径名location
。
例如:
location ~* ^/fileman(/.+\.php)$
{
root /var/www/mysite.com;
try_files $uri =405;
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $1;
fastcgi_pass unix:/var/run/php7-fpm-chroot-filemanager.sock
}