Aiden
Aiden

Reputation: 399

NGINX - No input file specified

Just want to let everyone know before I posted this question I checked every single thread on stackoverflow about this issue.

The aim:

Run two apps under one domain, first app on the root (/) and second app under the URI (/learn).

http://example.com/ - first app
http://example.com/learn - second app

The problem:

The main app works perfectly, but the learn app is showing a white page with "No input file specified.".

My file structure:

/srv/users/serverpilot/apps/main/public/index.php
/srv/users/serverpilot/apps/learn/public/index.php

My NGINX configuration:

root "/srv/users/serverpilot/apps/main/public";

location ^~ /learn {
    root    "/srv/users/serverpilot/apps";
    try_files   $uri /learn/public/index.php?$query_string;
    location ~ \.php$ {
        add_header X-debug-message $document_root$fastcgi_script_name always;
        include       fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass  unix:/srv/users/serverpilot/run/learn.php-fpm.sock;
    }
}

location / {
    try_files     $uri $uri/ /index.php?$args;
    location ~ \.php$ {
        include       fastcgi_params;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass  unix:/srv/users/serverpilot/run/main.php-fpm.sock;
        try_files     $uri =404;
    }
 }

In addition:

  1. I know the fastcgi_pass sockets are working because I've been running these two apps under different domains but in the same server in question.
  2. I added the add_header X-debug-message $document_root$fastcgi_script_name" always; to see what the response header would show, and it shows that the SCRIPT_FILENAME is /srv/users/serverpilot/apps/learn/public/index.php which exists and is the exact file I am trying to run.

Upvotes: 3

Views: 6583

Answers (1)

Aiden
Aiden

Reputation: 399

Oh lordy! What a wild hunt!

Okay the reason this configuration wasn't working is because aside from fastcgi_params you can also set php_value[doc_root] which will overwrite your $document_root which is commonly used in the SCRIPT_FILENAME parameter. So check your php.ini files always to make sure php_value[doc_root] is not set when you have apps that are being served from different directories otherwise it just wont pick them up. In the case that you are just serving a single app from a single directory you need not worry.

Upvotes: 2

Related Questions