perusio / drupal-with-nginx

Running Drupal using nginx: an idiosyncratically crafted bleeding edge configuration.
855 stars 246 forks source link

Redirect module doesn't works on nginx #154

Open MXTcomunica opened 10 years ago

MXTcomunica commented 10 years ago

I all,

First of all EXCUSE ME guys, I'm here after no success in other places like https://drupal.org/node/2174961 and http://drupal.stackexchange.com/questions/102176/redirect-does-not-work-on-nginx

but I'm desperately looking for an answer. And the first knot to be untied is if my issue is due to a module incompatibility (redirect module) or a simple missing vhost configuration in nginx.

THE ISSUE:

I'm migrating an old site to Drupal 7 (using migrate module), and I've managed directly in code all old urls to redirect to new Drupal urls using redirect module (https://drupal.org/project/redirect), for example:

www.mysite.com/UserProfile.php?user=5

Redirects to:

www.mysite.com/it/community/peoples/mr-max

This works very fine on my dev environment with apache, but doesn't works on live environment with nginx.

At first try with old url, I received a blank page with the message "No input file specified."

So I've changed virtual host conf from:

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 $request_filename;
  fastcgi_pass php-fpm;
}

to:

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 index.php;
  fastcgi_pass php-fpm;
}

RESULT: no more "No input file specified." blank page, but redirect doesn't works and my front page is shown for all old urls.

Here's other settings from my virtual host, if can help:

location ~ \..*/.*\.php$ {
  return 403;
}
location ~ ^/sites/.*/private/ {
  return 403;
}
location ~ (^|/)\. {
  return 403;
}
location / {
  try_files $uri @drupal;
}
location @drupal {
  # For D7 and above:
  # Clean URLs are handled in drupal_environment_initialize().
  rewrite ^ /index.php;
}
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 index.php;
  fastcgi_pass php-fpm;
}

What kind of setting I have to change/add to the above conf to make redirect working correctly?

Thank you very much for helping me

perusio commented 10 years ago
  1. First what you have above is not the config suggested here.
  2. You'll have problems with URIs ending in .php. My suggestion is to export all redirects and use a mapdirective to do the redirects at the server level. I'm assuming that the redirects are fixed, i.e., they will never change since if I understood correctly it comes from an old site.
MXTcomunica commented 10 years ago

Perusio thank you for your answer,

Finally I've found a solution thanks to https://groups.drupal.org/node/405038

In nginx vhost the php location setting must be:

        location ~ \.php$ {
                error_page 418 = @rewrite;
                recursive_error_pages on;
                fastcgi_split_path_info ^[^=](.+\.php)(/.+)$;
                include fastcgi_params;
                if ( $uri = /index.php ) {
                        # not sure this conditional works, will have to check the debug logs
                        break;
                }
                if ( !-e $document_root$fastcgi_script_name) {
                        return 418;
                }
                #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_intercept_errors on;
                fastcgi_read_timeout 240;
                fastcgi_pass  127.0.0.1:9000;
        }

(source: http://wiki.nginx.org/Drupal)