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.

as stated above the uri isn't being passed to nginx. I've included the entire "try" block to show this.

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to displaying a 404.
    set $page_to_view "/index.php";
    try_files $uri $uri.php $uri/;
    # Uncomment to enable naxsi on this location
    # include /etc/nginx/naxsi.rules
}

So it's essentially saying "oh hey we did $uri.php and that file exists, let's server it instead of actually sending it to php."

and my fpm portion is below.

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
#   # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

#   # With php5-cgi alone:
#   fastcgi_pass 127.0.0.1:9000;
#   # With php5-fpm:
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

Pretty much stock. So what I don't get is why in the world nginx isn't doing it anymore. I know it was working with fastcgi under debian but now it isn't, and I lost my old config file due to a HDD crash and it's the one file I didn't backup before sending the drive back as I thought it'd be perfectly AOK to rewrite it.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

You don't say what URI you're trying to load but I'm going to assume it doesn't end in .php.

Your issue here is that you're not taking the try_files directive literally as the name implies. It is specifically try a file. It's documented as try_files file ... uri; meaning that only the last argument is going to be treated as a fall back causing an internal rewrite. Any argument before the last one is tested as a static file and if found is served as a static file.

This means you can do try_files $uri $uri/ $uri.php; but you cannot do try_files $uri $uri.php $uri/

share|improve this answer
    
I guess I was wrong, I thought that it'd do the rewrite as soon as it encountered the whole $uri.php. I guess I was wrong thanks for the help. Marking this one as correct then. –  133794m3r Dec 24 '13 at 22:04

try replacing

location ~ \.php$ {

with

location ~ \.php {

and $document_root with actual dir where php file is placed

for ex.

fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
share|improve this answer
    
why downvote ? I have working setup which is working with this configuration. –  pragnesh Dec 24 '13 at 6:05

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.