ExpressionEngine CMS
Open, Free, Amazing


This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

How to remove index.php? on NGINX?

October 05, 2008 6:11pm

Subscribe [3]
  • #1 / Oct 05, 2008 6:11pm

    MediaGirl Inc.'s avatar

    MediaGirl Inc.

    186 posts

    I’m needing help removing index.php? completely from the URL on a server running NGINX instead of Apache.

    I found this as it relates to removing it for a CI isntall.

    Does anyone have how-to steps for an Expression Engine install?

    Thank you, Anna

  • #2 / Apr 04, 2009 9:53am


    7 posts

    Hi I don’t have the steps for a how to but I’m running nginx.
    I’ve posted my conf file for this vhost. It appears to run but I’m very new to expression engine so any feedback would be appreciated. This is also only for a single ee site.

    Force URL query is off. (was on with urls like index.php?/

    Once done, blank out the home page script name, in general conf. For me the links in templates where I’d used; {path='news/index'}, needed that to be blank to finally get no index.php in generated links.

    Nginx conf file, note I’m using vhosts and a params file.

    server {
      listen 80;
      index index.html index.php;
      root /home/user/public_html;
     #Support non-www
     if ($host ~* www\.(.*)) {
        set $host_without_www $1;
        rewrite ^(.*)$ <a href="$1">$1</a> permanent; # $1 contains '/foo', not ''
    #handles the tld issue.
      if ($host != '' ) {
        rewrite  ^/(.*)$  <a href="$1">$1</a>  permanent;
    #Maintenance mode from capistrano deploy
      if (-f $document_root/maintenance.html) {
        rewrite  ^(.*)$  /maintenance.html last;
      # If the file exists as a static file serve it directly without
      # running all the other rewite tests on it
      # serve static files directly
      location ~* ^.+\.(jpg|jpeg|gif|png|ico)$ {
        access_log        off;
        expires           30d;
      #If the file physically exists, serve it… ifs are bad in nginx though, there is a better way of doing this.
      if (-f $request_filename) {
      #EE customised rule, skip system folder and images folder, by rights images and system should of been served by now.
    #Note the question mark still…
      if ($request_filename !~ (system|images|robots\.txt|index\.php.*) ) {
         rewrite ^/(.*)$ /index.php?/$1 last;
      #Attempt to fix path_info, leaving the question mark works and covers testing domain.
      location /index.php {
        set  $script     $uri;
        set  $path_info  "";
        if ($uri ~ "^(.+\.php?)(/.+)") {
         set  $script     $1;
         set  $path_info  $2;
      #Finally mop up with anything left sent to the php-fpm engine.
    error_page 404 /index.php;
      location ~* .php$ {
        fastcgi_index index.php;
        include /usr/local/nginx/conf/fastcgi_params;
        #Added for EE
        fastcgi_param PATH_INFO       $path_info;

    Path info setting from this post:

    I hope that helps you or anyone else get EE running on nginx. I’ll also be doing the same for litespeed, but suspect no issues arise there.



  • #3 / May 08, 2009 6:17pm

    Lost Cause's avatar

    Lost Cause

    9 posts

    And here’s how I do mine (simple example):

    server {
             listen  80;
             rewrite  ^/(.*) <a href="$1">$1</a> permanent;
    server {
             listen  80;
             server_name  <a href=""></a>;
             access_log  /home/username/public_html/;
             error_log  /home/username/public_html/;
             root /home/username/public_html/;
             gzip  on;
             gzip_http_version  1.1;
             gzip_vary  on;
             gzip_min_length  1000;
             gzip_buffers  16 8k;
             gzip_comp_level  1;
             gzip_proxied  any;
             gzip_disable  "MSIE [1-6]\.";
             gzip_types  text/plain text/css application/x-javascript text/javascript application/xml+rss application/json;
             # set 404 page to an EE error template page
             error_page  404  /site/404;
             location ~* \.(jpg|jpeg|gif|png|ico)$ {
                                                     # give missing images a simple plain 404 error page
                                                     error_page  404  /404.html;
                                                     access_log        off;
                                                     expires           30d;
             location / {
                          index  index.php index.html;
                          # send url to index.php and append the requested uri to the end unless the file/directory exists
                          if (!-e $request_filename){
                            rewrite ^/(.*)$ /index.php?/$1? last;
             # This location is for our EE index.php gateway
             location /index.php {
                                   include /usr/local/nginx/conf/fastcgi_params;
                                   set $script     $uri;
                                   set $path_info  $uri;
                                   # this will set the path_info when it exists as query string: /index.php?/something/here
                                   if ($args ~* "^(/.+)$") {
                                      set $path_info  $1;
                                   fastcgi_index index.php;
                                   fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                                   fastcgi_param PATH_INFO $path_info;
             # This will process any other php files as usual
             location ~* \.php$ {
                                  include /usr/local/nginx/conf/fastcgi_params;
                                  fastcgi_index index.php;
                                  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                                  fastcgi_param PATH_INFO $fastcgi_script_name;
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases