ScaleScaleScaleScale

Tips / Nginx


Nginx configuration for Drupal

Drupal

After searching over the net, I found several guides about Nginx + Drupal configuration, and this was the one that worked perfectly good in my test enviroment. This rewrite rules are for Drupal + Nginx using PHP-FPM as php parser, in this guide we will assume that you have nginx, php-fpm and all the stuff working fine.

So, what you really need is just adding this location blocks inside the server block configuration for the virtualhost:

server {
...
...
...

location / {
                # This is cool because no php is touched for static content
                try_files $uri @rewrite;
        }

        location @rewrite {
                # Some modules enforce no slash (/) at the end of the URL
                # Else this rewrite block wouldn't be needed (GlobalRedirect)
                rewrite ^/(.*)$ /index.php?q=$1;
        }

        location ~ .php$ {
                fastcgi_split_path_info ^(.+.php)(/.+)$;
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_intercept_errors on;
                fastcgi_pass unix:/tmp/phpfpm.sock;
        }

...
...
...
}

Then restart nginx:

service nginx restart

Need more information?: Insready | Nginx Wiki

Popular search terms:

  • core/install php nginx rewrite in drupal
profile

Esteban Borges

Linux Geek, Webperf Addict, Nginx Fan. CTO @Infranetworking