WordPress、nginx 代理和子目录:wp-login.php 重定向到域 [英] WordPress, nginx proxy and subdirectory: wp-login.php redirects to domain

查看:44
本文介绍了WordPress、nginx 代理和子目录:wp-login.php 重定向到域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 NGINX 配置中,WordPress 博客位于私人服务器上.我的 NGINX 公共服务器代理私有服务器的内容 https://www.example.com/blog/.

In my NGINX configuration, a WordPress blog is on a private server. My NGINX public server proxies the private server's content for https://www.example.com/blog/.

location ^~ /blog/ {    # A "subdirectory", hiding a proxied server

    proxy_pass              http://192.168.0.5:80/;    # The blog resides in the 
                                                       # private's web root, 
                                                       # not in a subdirectory
    proxy_set_header        Host $host;
    proxy_set_header        X-Real-IP $remote_addr;
    proxy_redirect          off;
}

博客在调用域和子目录时完美呈现.启动 wp-login 不会生成 redirect GET 字段.

The blog is perfectly rendered on calling the domain and subdirectory. Bringing up wp-login does not generate a redirect GET field.

https://www.example.com/blog/wp-login.php

我的 siteurl 和我的 home 变量都设置为带有子目录的域.

My siteurl and my home variables are both set to the domain with subdirectory.

但是,在成功登录后,我可能会看到仪表板,但浏览器中的 URL 被重写为 https://www.example.com/wp-admin,导致在使用仪表板时出现问题.

However, after a successful login, I may see the dashboard, but the URL in my browser gets rewritten to https://www.example.com/wp-admin, causing problems on using the dashboard.

如何配置 WP 以将 URL 重写到子目录,尽管博客位于代理的私人服务器上?

How do I configure WP to rewrite the URL to the subdirectory, although the blog is on a proxied private server?

(服务器中的子目录必须对称吗?)

(Do the subdirectories in the servers have to be symmetrical?)

推荐答案

我也遇到了同样的问题,我找到了一种解决方法,要解决此问题,请将以下代码添加到 wp-config.php

I have also met with same problem, I found a workaround, to fix the issue, add below code to wp-config.php

$_SERVER['REQUEST_URI'] = str_replace("/wp-admin/", "/blog/wp-admin/",  $_SERVER['REQUEST_URI']);

这篇关于WordPress、nginx 代理和子目录:wp-login.php 重定向到域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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