3

I'm migrating an old site to Drupal (using migrate module), and I've managed directly in code all old urls to redirect to new Drupal urls using redirect module, 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?

8
  • 2
    This question appears to be off-topic because it is about Drupal, but about nginx.
    – Mołot
    Feb 4, 2014 at 10:31
  • 1
    I'm asking specific configurations to make Drupal and Drupal redirect module works on nginx, where else would I ask? There is also a specific tag 'nginx' here: what should this be used for?
    – MXT
    Feb 4, 2014 at 10:41
  • On Drupal.org, in issue queue if it's incompatibility between a module and server? On Server Fault if you don't know how nginx configuration works? Here if you know how server config works and just have problem with implementing proper stuff in module.
    – Mołot
    Feb 4, 2014 at 10:47
  • 1
    @MXT Redirect doesn't have a stable release yet, so this is very likely to be a bug report (which we can't help with here). I see you've actually posted it as such on Drupal.org already, that will most likely remain your best line of enquiry. Even Perusio's Drupal conf for Nginx has no special processing for the Redirect module, so either your general Nginx conf is incorrect (though I can't see anything wrong with it at a glance), or there's something amiss in the Redirect module. I'm not sure you'll get much help with either of those here I'm afraid, not really what we deal with
    – Clive
    Feb 4, 2014 at 10:53
  • Ok guys excuse me, I'm just desperately looking for an answer. I can't know if it's a module incompatibility (yet no answers on d.org issue queue) or a simple missing vhost configuration in nginx: I'm not so skilled in nginx: just for this I was here to ask and try to find an answer that maybe someone more skilled than me can easy provide. But ok you are right, I'll try to redirect my search elsewhere :)
    – MXT
    Feb 4, 2014 at 11:06

2 Answers 2

3

Finally, someone redirected me to the right place

Here's the missing code that does the trick:

location ~ \.php$ {
            error_page 418 = @rewrite;
            recursive_error_pages on;

            fastcgi_split_path_info ^[^=](.+\.php)(/.+)$;
            include fastcgi_params;

            if ( $uri = /index.php ) {
                    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

(link suggested in https://groups.drupal.org/node/405038)

0
0

I got a similar problem : migrating old site with php extension in Urls, and using Redirect module to preserve SEO, nginx returned "File not found".

The above solution did not work for my config. Instead that one did the trick :

location ~ \.php$|^/update.php {
    #old urls with php extension redirect
    if ($request_uri ~ .*.php.*) {
      error_page 404 =  @rewrite;
    }

    fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $request_filename;
    fastcgi_intercept_errors on;
    fastcgi_read_timeout 60;
    include fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.