Search code examples
phpdrupalnginxdrupal-7clean-urls

How to set up Clean url for Drupal with Nginx in localhost


I setup a nginx server in my localhost So now I want to enable clean url for this server

(Change localhost/drupalsite/?q=abc to localhost/drupalsite/abc)

I have tried some tutorials but thet don't work for me

http://wiki.nginx.org/Drupal
https://drupal.org/node/976392
http://richardbanks.net/blog/2012/11/nginx-url-rewrites-the-correct-method

This is some basic config in nginx.conf file

server {
        listen       8080;
        server_name  localhost;

        #charset koi8-r;

        #access_log  /var/log/nginx/host.access.log  main;

        location / {
            root   /srv/nginx/www/nginx_htdocs/;
            index  index.html index.htm index.php;

        }


        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /srv/nginx/www/nginx_htdocs/;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #fastcgi_param SCRIPT_FILENAME $request_filename;
            #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param  SCRIPT_FILENAME  /srv/nginx/www/nginx_htdocs/$fastcgi_script_name;

            include        fastcgi_params;
        }

        #--------------- TUNG CUSTOM





        #------------- END CUSTOM

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

Solution

  • Here's a gist of a full configuration that works very well with Drupal's clean URL's