I've been following the Nginx + PHP-FPM + APC = awesome tutorial to setup nginx. The performance gains look well worth the battle so I thought I would try it on my laptop before moving to a production server.
So far everything has gone well, I can serve up static content and display a simple php file calling phpinfo();
However when I try installing drupal firefox the install.php file will download in the download manager (raw php code) instead of being displayed in the browser.

Is there anything that might cause nginx not to send files to php for processing?

No doubt I have to tweak my nginx.conf, but I don't have much knowledge on this. I've tried tweaking a few things but so far no luck. Any help would be greatly appreciated.

Here is my nginx.conf

server {
    listen 80;
    server_name localhost;
 
    access_log  /var/log/nginx_access.log  main;
    error_log  /var/log/nginx_error.log debug;


 
    root /var/www/default/pub;
    index index.php;
 
    if (!-e $request_filename) {
        rewrite ^/(.*)$ /index.php?q=$1 last;
    }
 
    error_page 404 index.php;
 
    # hide protected files
    #location ~* \.(engine|inc|info|install|module|profile|po|sh|.*sql|theme|#tpl(\.php)?|xtmpl)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template)#$ {
   #   deny all;
   # }
 
    # hide backup_migrate files
    location ~* ^/files/backup_migrate {
      deny all;
    }
 
    # serve static files directly
    location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico)$ {
        access_log        off;
        expires           30d;
    }  
 
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
    }
}

Comments

brainless’s picture

Hello,
We have shifted to gentoo + nginx on Amazon EC2 since sometime now. Really Really good I must say.
We do not run Drupal though, custom CMS. But Drupal is my personal hobby. Anyways here is a config that does work:

server {
  listen                          80;
  server_name                     drupal6;
  root                            /srv/drupal6;
  
  location / {
    root                          /srv/drupal6;
    index                         index.php;
    if (-f $request_filename) {
      break;
    }
    
    if ($request_uri = /favicon.ico) {
      break;
    }
    if (!-f $request_filename) {
      rewrite ^/(.*)$  /index.php?q=$1 last;
    }
  }
  
  location ~ \.php$ {
    root                          /srv/drupal6;
    fastcgi_pass                  127.0.0.1:8888;
    fastcgi_index                 index.php;
    fastcgi_param                 SCRIPT_FILENAME  /srv/drupal6$fastcgi_script_name;
    include                       fastcgi_params;
  }
}
brainless’s picture

I think a lethal combo of nginx, PHP-cgi, memcache and APC (file stat set to 0) can do wonders for a high traffic website. Plus I am not sure exactly how much, but Gentoo adds that bang for your buck. We used to run a website on 2 small EC2s, with Apache, Debian. We shifted to nginx, Gentoo and we could deliver the same performance on a single small EC2.
Now we are trying to do the same for a website which has about 7 Million Page Views/month. These are custom CMSes I am taking about but then I think Drupal + Static Cache and some fine tuning (use AJAX load wherever possible for example) can really run a site very very fast.
I intend to try getting a benchmark here but I am sure we can get a much better performance compared to usual Apache + mod_php setup.