too many redirects for wordpress on nginx with apache2

tan*_*ngo 4 php apache wordpress nginx

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.

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;
        }
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

My /etc/hosts:

127.0.0.1       localhost
127.0.0.1       ubuntu
127.0.1.1       testblog.com
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

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.

Ric*_*ith 5

如果 Apache2 正在运行 WordPress,则需要配置nginx为代理所有内容。目前nginx,Apache2 和 Apache2 都将 URI 重写为/index.php,因为nginx首先这样做,WordPress 永远不会看到原始 URI。

从这个开始:

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;
    }
}
Run Code Online (Sandbox Code Playgroud)

如果您决定允许一些静态 URI 被nginx罚款。但是你不能让nginxURI 映射到,/index.php因为那是行不通的。