too many redirects for wordpress on nginx with apache2

I have just installed wordpress on ubuntu 14.04 LTS. Nginx acts as reverse proxy for apache2.

wp-admin is working fine, but I am unable to open the homepage.

Read More

Nginx Server Code:

server {
        listen 80;

        root /var/www/html/testblog;
        index index.php index.html index.htm;

        server_name testblog.com;

        location / {
                # try_files $uri $uri/ =404;
                try_files $uri $uri/ /index.php?q=$uri&$args;
        }

        error_page 404 /404.html;

        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
                root /usr/share/nginx/html;
        }

        location ~ .php$ {
                proxy_set_header X-Real-IP  $remote_addr;
                proxy_set_header X-Forwarded-For $remote_addr;
                proxy_set_header Host $host;
                proxy_pass http://127.0.0.1:8182;
        }

        location ~ /.ht {
                deny all;
        }
}

Apache Virtual Host Conf:

<VirtualHost *:8182>
        ServerName testblog.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/testblog

        ErrorLog ${APACHE_LOG_DIR}/errortest.log
        CustomLog ${APACHE_LOG_DIR}/accesstest.log combined
</VirtualHost>

My /etc/hosts:

127.0.0.1       localhost
127.0.0.1       ubuntu
127.0.1.1       testblog.com

I have all the wp files in the folder /var/www/html/testblog/.

testblog.com/wp-admin: working fine.

testblog.com: giving too many redirects.

Here is my settings page:

I guess my settings are correct. I have tried defining WP_HOME and WP_SITEURL in wp-config.php, but no luck.

My /var/www/html/testblog/.htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

testblog.com/wp-admin: working.

testblog.com: giving too many redirects error

Any help is highly appreciated.

Edit: I have already disabled all the plugins.

Related posts

Leave a Reply

1 comment

  1. If Apache2 is running WordPress, you need to configure nginx to proxy everything. At the moment you have both nginx and Apache2 rewriting URIs to /index.php, and because nginx does it first, WordPress never sees the original URI.

    Start with this:

    server {
        listen 80;
        server_name testblog.com;
    
        location / {
            proxy_set_header X-Real-IP  $remote_addr;
            proxy_set_header X-Forwarded-For $remote_addr;
            proxy_set_header Host $host;
            proxy_pass http://127.0.0.1:8182;
        }
    }
    

    And if you decide to allow some of the static URIs to be served by nginx fine. But you can’t let nginx map URIs to /index.php because that will not work.