Eugeny / ajenti-v

Virtual Hosting addon for Ajenti
ajenti.org/#product-ajenti-v
MIT License
225 stars 79 forks source link

How to create custom nginx config for drupal? #61

Closed ghost closed 10 years ago

ghost commented 10 years ago

I read custom nginx configuration for wordpress on http://support.ajenti.org/topic/353409-setting-up-a-php-website-with-ajenti-v-wordpress-example/

So I try create custom conf for drupal using this guide http://wiki.nginx.org/Drupal

I copied this code to Advanced Tab

        # Enable compression, this will help if you have for instance advagg‎ module
        # by serving Gzip versions of the files.
        gzip_static on;

        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        location ~ \..*/.*\.php$ {
                return 403;
        }

        # No no for private
        location ~ ^/sites/.*/private/ {
                return 403;
        }

        # Block access to "hidden" files and directories whose names begin with a
        # period. This includes directories used by version control systems such
        # as Subversion or Git to store control files.
        location ~ (^|/)\. {
                return 403;
        }

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

        location @rewrite {
                # You have 2 options here
                # For D7 and above:
                # Clean URLs are handled in drupal_environment_initialize().
                rewrite ^ /index.php;
        }

        # Fighting with Styles? This little gem is amazing.
        # This is for D7 and D8
        location ~ ^/sites/.*/files/styles/ {
                try_files $uri @rewrite;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }

On Content - Advanced - Custom Configuration I added

fastcgi_split_path_info ^(.+\.php)(/.+)$;
include fastcgi_params;
fastcgi_intercept_errors on;

When I check /etc/nginx/conf.d/mysite.conf the configuration become;

#AUTOMATICALLY GENERATED - DO NO EDIT!

server {
    listen *:80;

    server_name mysite.com example.com;

    access_log /var/log/nginx/mysite.access.log;
    error_log /var/log/nginx/mysite.error.log;

    root /srv/mysite;
    index index.html index.htm index.php;

            # Enable compression, this will help if you have for instance advagg‎ module
        # by serving Gzip versions of the files.
        gzip_static on;

        location = /favicon.ico {
                log_not_found off;
                access_log off;
        }

        location = /robots.txt {
                allow all;
                log_not_found off;
                access_log off;
        }

        location ~ \..*/.*\.php$ {
                return 403;
        }

        # No no for private
        location ~ ^/sites/.*/private/ {
                return 403;
        }

        # Block access to "hidden" files and directories whose names begin with a
        # period. This includes directories used by version control systems such
        # as Subversion or Git to store control files.
        location ~ (^|/)\. {
                return 403;
        }

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

        location @rewrite {
                # You have 2 options here
                # For D7 and above:
                # Clean URLs are handled in drupal_environment_initialize().
                rewrite ^ /index.php;
        }

        # Fighting with Styles? This little gem is amazing.
        # This is for D7 and D8
        location ~ ^/sites/.*/files/styles/ {
                try_files $uri @rewrite;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                expires max;
                log_not_found off;
        }

    location ~ \.php$ {

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
       include fastcgi_params;
       fastcgi_intercept_errors on;

        fastcgi_index index.php;
        include fcgi.conf;
        fastcgi_pass unix:/var/run/php-fcgi-mysite-php-fcgi-0.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    }

}

I run Clean URL test on drupal http://mysite.com/?q=admin/config/search/clean-urls But Clean URL test still failed.

What I missed here?

ghost commented 10 years ago

Oh I found the culprit that make Clean URL test failed we should not add this line

include fastcgi_params;

So now my drupal site has Clean URL :)

kargapoltsev commented 9 years ago

I have a problem. If I open the main page, downloaded index.php. All other pages open normally.

wfpaisa commented 9 years ago

Hello Reproduce all the steps and still did not work - CleanURL,

please help.

my conf.d:

#AUTOMATICALLY GENERATED - DO NO EDIT!

server {
    listen *:80;

    server_name site.teractivo.com;

    access_log /var/log/nginx/siteteractivocom.access.log;
    error_log /var/log/nginx/siteteractivocom.error.log;

    root /srv/teractivo/site/;
    index index.html index.htm index.php;

    client_max_body_size 128M;
fastcgi_read_timeout 300;

    location ~ [^/]\.php(/|$) {
        fastcgi_index index.php;
        include fcgi.conf;
        fastcgi_pass unix:/var/run/ajenti-v-php-fcgi-siteteractivocom-php-fcgi-0.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

    }

}