我使用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
在我的hosts文件中,我将2个域名: testapp.com和test.comredirect到127.0.0.1 。
我的networking文件都存储在/www 。
从上面的设置,如果我访问test.com/phpinfo.php和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这个事实来validation,这意味着该文件存在并且权限是正确的。
为什么会发生这种情况,以及为testapp.com v-host打破的根本原因是什么?
只是我的调查更新:
我已经在php-fpm.conf注释掉了chroot和chdir来缩小这个问题的范围
如果我删除了testapp.com的location ~ \.php$ ,那么nginx会发送一个包含PHP代码的bin文件。 这意味着在nginx方面,事情是好的。
问题在于,传递给PHP-FPM时,必须将文件path加以修改。
说了这么多,很奇怪的是, default_server v-host可以正常工作,因为它的根目录是/www ,因为根目录是/www/app/www ,所以testapp.com v-host不能正常工作。
问题解决了。
在我的php.ini ,我有:
doc_root = /www;
这意味着所有的php请求都会将/www添加到文件的开头,这是造成问题的原因。 我也已经在php-fpm.conf注释了chroot和chdir ,因为它们也会在文件path的开头添加额外的位。
到目前为止一切正常,但是,我会做更多的研究,让chroot和chdir工作来确保安装。
因此,对于test.com,您正在碰到第一个具有/ www / app / www的文件path的服务器块。
对于testapp.com,你正在打/ www,然后希望FPM知道你想要去/www/www/app/www/index.php
哪一个不会发生。 你可以分享你的fpmconfiguration的细节? 特别是chroot和chdir部分?