I am running Ubuntu Desktop 12.04 with nginx 1.2.6. PHP is PHP-FPM 5.4.9.
This is the relevant part of my 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;
}
}
}
Relevant bits from 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
In my hosts file, I redirect 2 domains: testapp.com
and test.com
to 127.0.0.1
.
My web files are all stored in /www
.
From the above settings, if I visit test.com/phpinfo.php
and test.com/app/www
, everything works as expected and I get output from PHP.
However, if I visit testapp.com
, I get the dreaded No input file specified.
error.
So, at this point, I pull out the log files and have a look:
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"
This baffles me because I have checked again and again and /www/app/www/index.php
definitely exists! This is also validated by the fact that test.com/app/www/index.php
works which means the file exists and the permissions are correct.
Why is this happening and what are the root causes of things breaking for just the testapp.com
v-host?
Just an update to my investigation:
I have commented out chroot
and chdir
in php-fpm.conf
to narrow down the problem
If I remove the location ~ \.php$
block for testapp.com
, then nginx will send me a bin file which contains the PHP code. This means that on nginx's side, things are fine.
The problem is that something must be mangling the file paths when passing it to PHP-FPM.
Having said that, it is quite strange that the default_server
v-host works fine because its root is /www
, where as things just won't work for the testapp.com
v-host because the root is /www/app/www
.
Problem solved.
In my
php.ini
, I had:This meant that all php request would have
/www
added to the beginning of the file, which was causing problems. I have also since commented outchroot
andchdir
inphp-fpm.conf
as they will also add extra bits to the beginning of file paths.So far everything works, however, I will be doing more research for getting
chroot
andchdir
to work to secure the installation.So, for test.com you're hitting the first server block which has the documentroot of /www/app/www.
For testapp.com you're hitting /www, and then hoping that FPM figures out you wanna go to /www/www/app/www/index.php
Which is not going to happen. Can you share the specifics of your fpm config? Specifically the chroot and chdir part?