我正在使用PHP 5.3.9和Nginx建立一个新的服务器,所以我使用PHP-fpm SAPI选项编译PHP.它本身在Nginx中使用以下服务器条目很有效:
server {
listen 80;
server_name domain.com www.domain.com;
root /var/www/clients/domain.com/www/public;
index index.PHP;
log_format gzip '$remote_addr - $remote_user [$time_local] "$request" $status $bytes_sent "$http_referer" "$http_user_agent" "$gzip_ratio"';
access_log /var/www/clients/domain.com/logs/www-access.log;
error_log /var/www/clients/domain.com/logs/www-error.log error;
location ~\.PHP${
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME /var/www/clients/domain.com/www/public$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/Nginx/fastcgi_params;
}
}
它很好地服务我的PHP文件.为了增加安全性,我想chroot我的FPM实例,所以我在这个FPM实例的conf文件中添加了以下行:
# FPM config
chroot = /var/www/clients/domain.com
并更改了Nginx配置:
#Nginx config for chroot
location ~\.PHP${
fastcgi_pass 127.0.0.1:9001;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME www/public$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/Nginx/fastcgi_params;
}
通过这些更改,Nginx为我提供了任何PHP脚本的File not found消息.查看错误日志,我可以看到它将根路径添加到我传递给fastcgi的DOCUMENT_ROOT变量,因此我尝试在位置块中覆盖它,如下所示:
fastcgi_param DOCUMENT_ROOT /www/public/;
fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
但我仍然得到相同的错误,并且调试日志显示发送到PHP-FPM的完整,未经过批次的路径.
为了让这个工作,我错过了什么?
最佳答案
看起来你忘记了/.
原文链接:https://www.f2er.com/nginx/435254.htmlfastcgi_param SCRIPT_FILENAME www/public$fastcgi_script_name;
应该读:
fastcgi_param SCRIPT_FILENAME /www/public$fastcgi_script_name;