我正在运行带有 nginx 1.2.6 的 Ubuntu Desktop 12.04。PHP 是 PHP-FPM 5.4.9。
这是我的相关部分nginx.conf
:
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
server_name testapp.com;
root /www/app/www/;
index index.php index.html index.htm;
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
server {
listen 80 default_server;
root /www
index index.html index.php;
location ~ \.php$ {
fastcgi_intercept_errors on;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
}
相关位来自php-fpm.conf
:
; Chroot to this directory at the start. This value must be defined as an
; absolute path. When this value is not set, chroot is not used.
; Note: you can prefix with '$prefix' to chroot to the pool prefix or one
; of its subdirectories. If the pool prefix is not set, the global prefix
; will be used instead.
; Note: chrooting is a great security feature and should be used whenever
; possible. However, all PHP paths will be relative to the chroot
; (error_log, sessions.save_path, ...).
; Default Value: not set
;chroot =
; Chdir to this directory at the start.
; Note: relative path can be used.
; Default Value: current directory or / when chroot
chdir = /www
在我的主机文件中,我重定向了2 个域:testapp.com
和.test.com
127.0.0.1
我的网页文件都存储在/www
.
从上面的设置来看,如果我访问test.com/phpinfo.php
and test.com/app/www
,一切都会按预期进行,并且我会从 PHP 获得输出。
但是,如果我访问testapp.com
,我会得到可怕的No input file specified.
错误。
所以,在这一点上,我拉出日志文件看看:
2012/12/19 16:00:53 [error] 12183#0: *17 FastCGI sent in stderr: "Unable to open primary script: /www/app/www/index.php (No such file or directory)" while reading response header from upstream, client: 127.0.0.1, server: testapp.com, request: "GET / HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "testapp.com"
这让我很困惑,因为我检查了一遍又一遍,/www/app/www/index.php
确实存在!这也通过有效的事实得到验证,test.com/app/www/index.php
这意味着文件存在并且权限正确。
testapp.com
为什么会发生这种情况?仅v-host出现故障的根本原因是什么?
只是对我的调查的更新:
我已经评论出来并chroot
缩小问题范围chdir
php-fpm.conf
如果我删除location ~ \.php$
块testapp.com
,那么 nginx 将向我发送一个包含 PHP 代码的 bin 文件。这意味着在 nginx 方面,一切都很好。
问题是在将文件传递给 PHP-FPM 时一定有什么东西破坏了文件路径。
default_server
话虽如此, v-host 可以正常工作是很奇怪的,因为它的根是/www
,而 v-host 却不起作用,testapp.com
因为根是/www/app/www
.
问题解决了。
在我的
php.ini
,我有:这意味着所有 php 请求都会
/www
添加到文件的开头,这会导致问题。我也已经评论了 outchroot
和chdir
in,php-fpm.conf
因为它们还会在文件路径的开头添加额外的位。到目前为止一切正常,但是,我将进行更多研究以获取
chroot
并chdir
努力确保安装安全。因此,对于 test.com,您正在访问具有 /www/app/www 文档根目录的第一个服务器块。
对于 testapp.com,你正在点击 /www,然后希望 FPM 知道你想去 /www/www/app/www/index.php
这是不会发生的。你能分享一下你的 fpm 配置的细节吗?特别是 chroot 和 chdir 部分?