Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having issues with serving static files. It servers all my javascript/css/images just fine, with no issues, but it's returning a 404 for PHP files. If I visit the php file directly, it gives an 'input file not specified' error.

I do have PHP files configured within the virtual host on nginx, but I'm wondering if I have to do this further down the location tree also? Here is my current nginx configuration for the application:

server {
        listen          80;
        error_log       /home/clearpoint/http_error_log;

        location / {
                root    /home/clearpoint;
                index   index.htm index.html index.php;

        location /budget-calculator {
                fastcgi_param           SCRIPT_FILENAME $fastcgi_script_name;
                fastcgi_param           PATH_INFO       $fastcgi_script_name;
                include                 /etc/nginx/fastcgi_params;
                fastcgi_pass            unix:/tmp/cpbc.socket;

        location /budget-calculator/static {
                alias           /home/clearpoint/ClearPoint-Budget-Calc/static;

        location /budget-calculator/static/scripts/php/~\.php$ {
                include /etc/nginx/fastcgi_params;
                fastcgi_pass    unix:/tmp/php.socket;
                fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;

the test server url for the application being built:

Trying to get to the /scripts/php directory returns a 403 forbidden as expected, so the issue I think isn't that it can't find the files, it's that nginx isn't serving them as proper php.

EDIT: I rewrote the entire configuration (changed above). Now getting a 405 error, but that's progress.

EDIT AGAIN: If I manually define thge location of the scripts in the location / block and then manually set the SCRIPT_FILENAME, there are no problems.

I believe I am improperly using the $fastcgi_script_name, but at least I have a workaround while I determine the best course of action given the alias requirements.

share|improve this question
Is /scripts/php located in /budget-calculator? – quanta Oct 11 '11 at 16:41
no. budget-calculator is the url. scripts/php is located at /ClearPoint-Budget-Calc/static/scripts/php. It's finding the scripts/js folder for the javascript files with no issue. But that's why I have the alias set up for /budget-calculator/static/. – Tom Thorogood Oct 11 '11 at 16:45
What happens if you request<any_file>.php? Did you take a look at http_error_log? – quanta Oct 11 '11 at 16:51
I did just notice an error with the inner php directive, but it didn't help. All paths should read /home/ClearPoint-Budget-Calc/static/scripts/php - I checked the error log but there are no entries at all for today. Trying what you suggested: all file names, no matter whether or not exists, return the same "no input file specified" error. – Tom Thorogood Oct 11 '11 at 16:53
up vote 0 down vote accepted

Define SCRIPT_FILENAME in fastcgi_params:

fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;

and change your config file to something like this:

    location /budget-calculator {
        fastcgi_pass unix:/tmp/cpbc.socket;
        include /etc/nginx/fastcgi_params;

        location /budget-calculator/static {
            alias /home/clearpoint/ClearPoint-Budget-Calc/static;

            location ~ ^/budget-calculator/static/scripts/php/\.php$ {
                fastcgi_pass unix:/tmp/php.socket;

Notice that you must use ~ to matches a regular expressions.

share|improve this answer
I know this is much later, but I had a server migration so I haven't been able to get back to this. The problem is that $document_root$script_filename can't work, because actual path and $fastcgi_script_name are different, as there is an alias involved. Is there a way to just extract filename.php from $fastcgi_script_name? Then I can set $static_root$actual_filename as the param? – Tom Thorogood Oct 25 '11 at 14:52
I changed the server configuration - if I serve this from its own subdomain, instead of an aliased folder, this problem goes away. – Tom Thorogood Oct 25 '11 at 20:32

Your Answer


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.