EllisLab text mark
Advanced Search
     
How to remove index.php? on NGINX?
Posted: 05 October 2008 06:11 PM
Avatar
Joined: 2005-08-07
225 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.
http://ellislab.com/forums/viewthread/90231/#470327

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

Thank you, Anna

 Signature 

Anna Brown ~ {ExpressionEngine Developer} ~ {Portfolio} ~ {Facebook} ~ {Twitter} ~ Corrales/Albuquerque, New Mexico

Expert front-end ExpressionEngine programmer for creative agencies, designers & direct clients.

 
Posted: 04 April 2009 09:53 AM   [ # 1 ]   [ Rating: 0 ]
Joined: 2007-08-07
8 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
;
  
server_name domain.co.uk domain2.com domain3.org;
  
index index.html index.php;
  
root /home/user/public_html;
 
#Support non-www
 
if ($host ~* www\.(.*)) {
    set $host_without_www 
$1;
    
rewrite ^(.*)$ http://domain.co.uk$1 permanent; # $1 contains '/foo', not 'www.mydomain.com/foo'
  
}
#handles the tld issue.
  
if ($host != 'domain.co.uk' {
    rewrite  
^/(.*)$  http://domain.co.uk/$1  permanent;
  
}

#Maintenance mode from capistrano deploy
  
if (-f $document_root/maintenance.html{
    rewrite  
^(.*)$  /maintenance.html last;
    break;
  
}

  
# 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{
    
break;
  
}

  
#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_pass 127.0.0.1
:9000;
    
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: http://forum.slicehost.com/comments.php?DiscussionID=2950

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.

Cheers,

Colin

 Signature 

Colin Densem

 
Posted: 08 May 2009 06:17 PM   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-24
11 posts

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

server {
         listen  80
;
         
server_name  yourdomain.com;
         
rewrite  ^/(.*) http://www.yourdomain.com/$1 permanent;
       
}

server {
         listen  80
;
         
server_name  www.yourdomain.com;

         
access_log  /home/username/public_html/yourdomain.com/log/access.log;
         
error_log  /home/username/public_html/yourdomain.com/log/error.log;

         
root /home/username/public_html/yourdomain.com/public;

         
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?/$1last;
                      
}
                      
                    }
                      
         
# 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_pass 127.0.0.1
:9000;
                               
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_pass 127.0.0.1:9000;
                              
fastcgi_index index.php;
                              
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                              
fastcgi_param PATH_INFO $fastcgi_script_name;
                            
}
       }