Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Problem solved.

In my php.ini, I had:

doc_root = /www;

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 out chroot and chdir in php-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 and chdir to work to secure the installation.

share|improve this answer

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?

share|improve this answer
    
Can you elaborate why it is not going to happen? test.com has a root of /www where as testapp.com has a root of /www/app/www. I have updated my question as well :) –  F21 Dec 19 '12 at 5:40
    
try changing the chdir to just /. How nginx passes the variables, and how fpm reads the path are completely different. When you set the chdir to be /www, and then nginx sends something to fpm, it assumes the path nginx is sending, is AFTER the /www already. with a chdir of /www, testapp.com sees it as /www/www/app/www, test.com sees it as /www/www/ –  Vid Luther Dec 19 '12 at 6:03
    
nope, still no dice :( –  F21 Dec 19 '12 at 6:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.