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 have a simple nginx setup and things work fine.

I have set the index as follows:

index index.html index.php

The server_name is set to local.nginx. If i request http://local.nginx it works fine, but if i request http://local.nginx/index.php - the raw file is sent to the browser.

What is wrong?

Please see my config below:

server {
    listen       80;
    server_name  local.nginx;
    root         /var/www/local.nginx/;
    index       index.html index.php;

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

EDIT

I discovered this was only happening in chrome. After clearing the browser cache the problem disappeared. Can anyone explain what happened here ?

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

If while testing, your PHP configuration was not working, Chrome will have cached the raw .php file and continued to serve that.

Please be careful with your PHP configuration, especially if you'll be accepting uploads or saving any input to files in the document root, as it's possible to add path info to a url and get the PHP interpreter to execute it, e.g.

http://local.nginx/uploads/myfile.txt/oops.php

share|improve this answer
    
How do you prevent that with the configuration then? (the issue with the path)? –  Marty Wallace Feb 17 '13 at 21:40
1  
Assuming everything is running on the same box, then you can add this into that location block: try_files $uri =404; This will check if the file exists and if not return a 404. –  Alan Feb 17 '13 at 21:45
add comment

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.