【问题标题】:too many redirects for wordpress on nginx with apache2使用 apache2 的 nginx 上的 wordpress 重定向太多
【发布时间】:2016-06-09 20:52:53
【问题描述】:

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

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

Nginx 服务器代码:

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

<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:

127.0.0.1       localhost
127.0.0.1       ubuntu
127.0.1.1       testblog.com

我在文件夹 /var/www/html/testblog/ 中有所有 wp 文件。

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

testblog.com:重定向太多。

Here is my settings page:

我想我的设置是正确的。我曾尝试在 wp-config.php 中定义 WP_HOME 和 WP_SITEURL,但没有成功。

我的 /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: 提供太多重定向错误

非常感谢任何帮助。

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

【问题讨论】:

    标签: php wordpress apache nginx


    【解决方案1】:

    如果 Apache2 运行 WordPress,您需要配置 nginx 来代理所有内容。目前,nginx 和 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;
        }
    }
    

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

    【讨论】:

    • 老兄,就是这样。你能解释一下,为什么 wp-admin 可以,但主页不行。很抱歉,不能投票。
    • 还有一点,主页 (testblog.com) 可以正常打开。但是当我点击一个帖子说:testblog.com/sunny 这说:404 not found from Apache.
    • 我猜/wp-admin/index.php 不会像/index.php 那样生成重定向。另外,请查看at this page,了解为什么 Apache 可能无法正确处理漂亮的永久链接。
    • 看来您对 wp-admin/index.php 的看法是正确的。我发现我的 mod_rewrite 没有启用。启用后一切正常。感谢 Richard 提供的帮助和宝贵的时间。
    • 你能举个例子,wordpress安装在一个子文件夹中(例如/blog/)?我已经坚持了好几天了……我正在使用 Docker,也许你也知道一些。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-22
    • 2013-03-13
    • 2015-06-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多