Skip to content

Drupal clean URLs with nginx – the simple way

January 4, 2011

I know, it’s somehow old topics that i write these days – nginx is there since late 2004, but it’s the fact that all articles online doesn’t mention some important information about the installation and the configuration and some others tries to make it so complex plus the fact that the default configuration included with most dists. makes it confusing to understand it.

Simply – you must create a virtual host – new server { entry for drupal directory to get clean urls working !! – yes apache is so smart .
in the configuration file you can add the following block of lines and modify it to meet your env. and that’s damn fine:

server {
listen 80;
server_name Server2;
root /var/www/html/drpl;
index index.php;
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?q=$1 last;
}

location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

}

Note: the server_name value must differ from the main virtual host name – and must be defined in /etc/hosts with different IP and it should look like this:

127.0.0.1 localhost.localdomain localhost
192.168.1.10 server2.mylan server2

finally don’t forget to restart nginx ;) .

2 Comments leave one →
  1. January 7, 2011 4:15 pm

    another good way to get clean urls working with durpal without a server/virtual host entry is using this:

    location /drupal {
    if (!-e $request_filename) {
    rewrite ^(/drpl)(.*)$ /drupal/index.php?q=$2 last;
    # _____|_$1_|_$2____________________^
    }
    }

    the rewrite line splits the URI to base and args using ()s – and PHP assigns $1 to the 1st () and $2 to the second () which is the args then sends the $2 to the index.php .

Trackbacks

  1. Drupal Clean Urls With Nginx/Lighttpd | Nginx Lighttpd

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: