Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

As I'm trying to make my switch from Apache 2 to Nginx, I faced dozens of problems, and still fixing them. anyway, I'm trying to make them work, but no-luck yet. So I'm asking here looking for help/previous experience.

I used the default configurations to run PHP, and it works great when running PHP files only. but unfortunately codeigniter URL's doesn't end in *.PHP. So I think PHP-FPM doesn't treat my scripts as PHP files, since the URL doesn't end in *.PHP. I'm just guessing though.

So, Is there any possible way to make them work togather? it seems impossible to me, I tried lots of configurations(after modifying them to fit my environment, ofcource) but non of them worked with Codeigniter.

Hopefully posting my current configurations that works with normal php files, will lead to some solutions.
Note: This is the exact same one posted in Nginx's wiki page for Codeigniter framework.

server {
        server_name _;#_ to catch all requests.

        root /usr/share/nginx/www;
        index index.html index.php;

        # set expiration of assets to MAX for caching
        location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
                expires max;
                log_not_found off;

        location / {
                # Check if a file exists, or route it to index.php.
                try_files $uri $uri/ /index.php;

        location ~* \.php$ {
                fastcgi_index index.php;
                fastcgi_split_path_info ^(.+\.php)(.*)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

using the previous configuration for my /sites-enabled/default configuration makes PHP works but not codeigniter, all I get is white pages, and codeigniter's custom 404 when accessing non-existent files.

I also reconfigured config.php files like the following:

$config['base_url'] = "http://localhost/";
$config['index_page']   = "";
$config['uri_protocol'] = "REQUEST_URI";

I tried these configurations and lots of others, usually the same results.

Anyway, there are few points that will(hopefully) get me an answer:

1.I tried these configurations on Debian 6/Ubuntu 12.04

2.I'm running the latest php5-fpm , nginx from apt-get.

3.Something I notice, commenting out SCRIPT_NAME and SCRIPT_FILENAME(in fastcgi_params file) causes codeigniter to show an error. however commenting these on the current configuration above doesn't have any impact.

4.File permissions for all files under /usr/share is 777, I know it's insecure, but I'm using it for testing only.

share|improve this question
Did you reload nginx after changing your configuration? I don't see any obvious problems here. Also, if you get the white screen of death, check PHP's error log. – Michael Hampton Jul 30 '12 at 23:07
@MichaelHampton Yes, after every single change I use(as root) service nginx restart. – Rev3rse Jul 30 '12 at 23:09
What PHP errors are in your logs? – Michael Hampton Jul 30 '12 at 23:09
@MichaelHampton Nginx error logs? Nothing related at all. – Rev3rse Jul 30 '12 at 23:11
You should set up PHP to log errors, so that you can find out what it's doing. – Michael Hampton Jul 30 '12 at 23:13

I found the solution for this problem. It wasn't related to Codeigniter nor Nginx. the probem was within MySQL, since I auto-loaded database library which connects to MySQL upon requesting any page. MySQL itself wasn't installed anyway, that's why nothing works.

In Debain/Ubuntu all I did was apt-get install mysql-server mysql-client php5-mysql and then setting up mysql and restarting php-fpm service php5-fpm restart. and you're good to go.

share|improve this answer

The try_files is redirecting any non-existent url to index.php

The issue is that the block location ~ \.php is not taken into account.

Recopy everything inside this block into the block above, just after your try_files.

share|improve this answer

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.