使用apache2在nginx上进行wordpress的重定向过多 [英] too many redirects for wordpress on nginx with apache2

查看:274
本文介绍了使用apache2在nginx上进行wordpress的重定向过多的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在ubuntu 14.04 LTS上安装了wordpress. Nginx充当apache2的反向代理.

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

wp-admin工作正常,但无法打开主页.

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

Nginx服务器代码:

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虚拟主机配置:

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>

我的/etc/hosts:

My /etc/hosts:

127.0.0.1       localhost
127.0.0.1       ubuntu
127.0.1.1       testblog.com

我所有的wp文件都在/var/www/html/testblog/文件夹中.

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

testblog.com/wp-admin:工作正常.

testblog.com/wp-admin: working fine.

testblog.com:重定向过多.

testblog.com: giving too many redirects.

这是我的设置页面:

我猜我的设置是正确的.我曾尝试在wp-config.php中定义WP_HOME和WP_SITEURL,但是没有运气.

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

我的/var/www/html/testblog/.htaccess:

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:正常工作.

testblog.com/wp-admin: working.

testblog.com:出现太多重定向错误

testblog.com: giving too many redirects error

我们非常感谢您的帮助.

Any help is highly appreciated.

编辑:我已经禁用了所有插件.

I have already disabled all the plugins.

推荐答案

如果Apache2运行WordPress,则需要配置nginx来代理所有内容.目前,您同时具有nginx和Apache2将URI重写为/index.php的功能,并且由于nginx首先执行此操作,因此WordPress永远不会看到原始URI.

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.

从此开始:

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;
    }
}

如果您决定允许nginx提供某些静态URI,则可以.但是您不能让nginx将URI映射到/index.php,因为那是行不通的.

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.

这篇关于使用apache2在nginx上进行wordpress的重定向过多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆