Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/, 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/ 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 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/ so it points now to the real backup folder (/var/www/ -> (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/ 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, 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;
            rewrite ^/(.*)$1 permanent;


server {
       listen   80;
       access_log  /var/www/;
       error_log      /var/www/ info;
       root /var/www/;

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

        # 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/;

## 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/$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param  HTTP_HOST;
        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?

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


location / {
    try_files $uri $uri/ /index.php;
share|improve this answer
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/ and also chmod 755 to the same folder just to test and no differences :( Any ideas? – javipas Feb 3 '11 at 18:10
Add error log(/var/www/ info). – alvosu Feb 4 '11 at 3:59

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; there.

share|improve this answer
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 '11 at 16:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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