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

I'm trying out nginx and porting my existing apache configuration to nginx. I have managed to reroute the codeigniter url's successfully, but I'm having a problem with one particular controller whose name coincides with a directory in site root.

I managed to make my codeigniter url's work as it did in Apache except that, I have a particular url say http://localhost/hello which coincides with a hello directory in site root. Apache had no problem with this. But nginx routes to this directory instead of the controller.

My reroute structure is as follows

http://host_name/incoming_url => http://host_name/index.php/incoming_url

All the codeigniter files are in site root.

My nginx configuration (relevant parts)

location / {
    # First attempt to serve request as file, then
    # as directory, then fall back to index.html

    index index.php index.html index.htm;

    try_files $uri $uri/ /index.php/$request_uri;

    #apache rewrite rule conversion

    if (!-e $request_filename){
        rewrite ^(.*)/?$ /index.php?/$1 last;

    # Uncomment to enable naxsi on this location
    # include /etc/nginx/naxsi.rules

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

    # With php5-cgi alone:
    # With php5-fpm:
    #fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;


my relevant apache htaccess configuration

    # Set the default file for indexes
DirectoryIndex index.php

<IfModule mod_rewrite.c>
    # mod_rewrite rules
    RewriteEngine on
    # If the file is NOT the index.php file
    RewriteCond %{REQUEST_FILENAME} !index.php
    # If the file/dir is NOT real go to index
    RewriteCond %{REQUEST_FILENAME} !-f
    #RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]


I'm new to nginx and I need help in figuring out this directory conflict with the Controller name. I figured this configuration from various sources in the web, and any better way of writing my configuration is greatly appreciated.

share|improve this question
Can you post your Apache rewrites? – Pothi Oct 28 '13 at 11:05
@Pothi I have added the htaccess config parts related to the codeigniter rewrite. let me know if anything else is necessary. thanks – palerdot Oct 28 '13 at 11:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.