1

I'm moving a Wordpress blog from a Apache based webserver to a Nginx based webserver. Easy steps, I thought:

  • scp of the source WordPress folder, in this example, /var/www/example.com, which is transferred to a folder with the same name on the remote webserver. No problem with that.

  • mysqldump of the source WordPress database. No problem with that.

  • On the nginx webserver, I create a database (with the same name as the source one, just to keep everything equal).

  • I setup a default WP blog to see if everything is fine at this point. I create a proper
    /etc/nginx/sites-available/example.com config file (and link to sites-enabled, of course). That
    config file points to a diferent folder (/var/www/exampletemp)

  • Modify my Windows hosts file in order to test the new blog on the domain I'm interested in. The blog at example.com shows fine, the default WP blog of course, but with the right URLs.

  • And then the crucial steps. First I edit /etc/nginx/sites-available/example.com so it points now to the real backup folder (/var/www/example.com) -> (just change root locations and the fastcgi directive).

  • Then I create another database, restore the source database on this new one, edit wp-config.php file on the /var/www/example.com just in case there's something missing, and restart nginx.

What do I get?

A gorgeous, beautiful "ERROR 310: Too many redirects" :(

I can see the login page on www.example.com/wp-login.php, but my source users don't work and I can't get no access to the WordPress Dashboard. I've modified for example an admin account from phpMyadmin, setting up a new password and selecting the MD5 encryption, and although that has worked when I moved from Apache to Apache or Nginx to Nginx, this time it hasn't.

I really don't get why there is that Too many redirects error. I have try to disable all plugins (renaming the /wp-content/plugins to /wp-content/oldplugins, or disabling all of them with a SQL query) but no luck again.

Sorry for the long question. I hope I've made myself clear...

Edit: This is the nginx config file, just in case :)

server {

            listen   80;
            server_name  www.example.com;
            rewrite ^/(.*) http://example.com/$1 permanent;

           }


server {
       listen   80;
       access_log  /var/www/example.com/log/access.log;
       error_log      /var/www/example.com/log/error.log info;
       server_name     example.com;
       root /var/www/example.com;

       location / {
          index index.php;
          # if the requested file exists, return it immediately
          if (-f $request_filename) {
                  break;
          }

        # all other requests go to WordPress
        if (!-e $request_filename) {
           rewrite . /index.php last;
           }
      }

      ## Images and static content is treated different
      location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
               access_log        off;
               expires           30d;
               root /var/www/example.com;
      }


## Parse all .php file in the /var/www directory
    location ~ .php$ {
        fastcgi_split_path_info ^(.+\.php)(.*)$;
        fastcgi_pass   backend;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /var/www/example.com$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param  HTTP_HOST        example.com;
        fastcgi_param  QUERY_STRING     $query_string;
        fastcgi_param  REQUEST_METHOD   $request_method;
        fastcgi_param  CONTENT_TYPE     $content_type;
        fastcgi_param  CONTENT_LENGTH   $content_length;
        fastcgi_intercept_errors        on;
        fastcgi_ignore_client_abort     on;
        fastcgi_read_timeout 180;

    }


    ## Disable viewing .htaccess & .htpassword
    location ~ /\.ht {
        deny  all;
    }
}

I'm thinking in another answer to my question: The source WP folder on the Apache webserver has apache:apache as user:group, and after 'scping' that folder to my new Nginx webserver, that user and that group is no longer valid. I made the proper chown -R www-data:www-data to the new WP folder, but... could that be a hint to the answer?

1
  • Debug this with curl. "curl -v www.example.com 2>&1 | grep Location:". Lather, rinse, repeat and you'll see what is redirecting to what infinitely.
    – dialt0ne
    Feb 3, 2011 at 16:49

2 Answers 2

2

Try:

location / {
    try_files $uri $uri/ /index.php;
}
2
  • Well, after using that line instead of all the previous "location /" block now I get something different: 403 Forbidden. I've checked permissions, user:group, but I can't found anything strange. I've made chown -R www-data:www-data /var/www/example.com and also chmod 755 to the same folder just to test and no differences :( Any ideas?
    – javipas
    Feb 3, 2011 at 18:10
  • Add error log(/var/www/example.com/log/error.log info).
    – alvosu
    Feb 4, 2011 at 3:59
1

Does nginx pass a proper "Host" header to the FastCGI server? Wordpress checks this header and perform a redirect if it is not equal to a setting in the DB. It looks like you should check your /etc/nginx/fastcgi_params and set something like fastcgi_param HTTP_HOST example.com; there.

1
  • Mmm. Bad luck, hasn't work. I've edited the question in order to include the nginx config file for this site. Everything is just the same as the original, except for the real domain and its folder.
    – javipas
    Feb 3, 2011 at 16:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .