Drupal on nginx

After moving from apache to nginx, you might notice no matter what link you try to go to, you get what appears to be your home page. More than likely, clean urls are enabled and your .conf file isn’t set up to route them properly (since .htaccess rules are not used on nginx).

For D6

location / {


    root  /var/www/webroot/docroot;
    try_files $uri @rewrite; 
     autoindex off;
    index  index.html index.htm index.php;


  } 

  location @rewrite {
      rewrite ^/(.*)$ /index.php?q=$1;
}

For D8

location / {


    root  /var/www/webroot/docroot;
    try_files $uri $uri/ /index.php$query_string;
     autoindex off;
    index  index.html index.htm index.php;


  }

Reference
A more complete sample conf file with all the blocks defined, see here.

Leave a Reply

Your email address will not be published. Required fields are marked *