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/.
在我的NGINX配置中,WordPress博客位于一个私有服务器上。我的NGINX公共服务器代理私有服务器的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;
}
The blog is perfectly rendered on calling the domain and subdirectory. Bringing up wp-login does not generate a redirect GET field.
在调用域和子目录时,博客被完美地呈现出来。启动wp-login不会产生重定向GET字段。
https://www.example.com/blog/wp-login.php
https://www.example.com/blog/wp-login.php
My siteurl and my home variables are both set to the domain with subdirectory.
我的siteurl和我的home变量都被设置为带有子目录的域。
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.
但是,在成功登录之后,我可能会看到仪表板,但是我浏览器中的URL被重写到https://www.example.com/wp-admin,这导致使用仪表板出现问题。
How do I configure WP to rewrite the URL to the subdirectory, although the blog is on a proxied private server?
如何配置WP以重写到子目录的URL,尽管blog是在一个受代理的私有服务器上?
(Do the subdirectories in the servers have to be symmetrical?)
(服务器中的子目录必须对称吗?)
2 个解决方案
#1
11
I have also met with same problem, I found a workaround, to fix the issue, add below code to wp-config.php
我也遇到了同样的问题,我找到了一个解决方案,为了解决这个问题,在wp-config.php中添加下面的代码
$_SERVER['REQUEST_URI'] = str_replace("/wp-admin/", "/blog/wp-admin/", $_SERVER['REQUEST_URI']);
#2
8
WordPress uses two variables to define where it is hosted: WP_HOME
and WP_SITEURL
. Both can be set using the dashboard, but I prefer to set them in wp-config.php
:
WordPress使用两个变量来定义其托管位置:WP_HOME和WP_SITEURL。两者都可以使用仪表板进行设置,但我更喜欢在wp-config.php中进行设置:
define( 'WP_SITEURL', 'https://www.example.com/blog' );
define( 'WP_HOME', 'https://www.example.com/blog' );
It is usual to set an absolute URL (as above) which includes scheme and host name, but I prefer to use a relative URL when operating behind a reverse-proxy, like this:
通常设置一个包含scheme和主机名的绝对URL(如上所示),但在反向代理后操作时,我更喜欢使用一个相对URL,如下所示:
define( 'WP_SITEURL', '/blog' );
define( 'WP_HOME', '/blog' );
You can probably continue to run WordPress in the root of your private server (assuming it isn't accessed directly). Moving the private server down one level is a little more complicated and involves the web server configuration on both servers to be changed a little.
您可以继续在您的私有服务器的根上运行WordPress(假设它没有被直接访问)。将私有服务器向下移动一个级别要稍微复杂一些,并且需要对两个服务器上的web服务器配置稍加修改。
#1
11
I have also met with same problem, I found a workaround, to fix the issue, add below code to wp-config.php
我也遇到了同样的问题,我找到了一个解决方案,为了解决这个问题,在wp-config.php中添加下面的代码
$_SERVER['REQUEST_URI'] = str_replace("/wp-admin/", "/blog/wp-admin/", $_SERVER['REQUEST_URI']);
#2
8
WordPress uses two variables to define where it is hosted: WP_HOME
and WP_SITEURL
. Both can be set using the dashboard, but I prefer to set them in wp-config.php
:
WordPress使用两个变量来定义其托管位置:WP_HOME和WP_SITEURL。两者都可以使用仪表板进行设置,但我更喜欢在wp-config.php中进行设置:
define( 'WP_SITEURL', 'https://www.example.com/blog' );
define( 'WP_HOME', 'https://www.example.com/blog' );
It is usual to set an absolute URL (as above) which includes scheme and host name, but I prefer to use a relative URL when operating behind a reverse-proxy, like this:
通常设置一个包含scheme和主机名的绝对URL(如上所示),但在反向代理后操作时,我更喜欢使用一个相对URL,如下所示:
define( 'WP_SITEURL', '/blog' );
define( 'WP_HOME', '/blog' );
You can probably continue to run WordPress in the root of your private server (assuming it isn't accessed directly). Moving the private server down one level is a little more complicated and involves the web server configuration on both servers to be changed a little.
您可以继续在您的私有服务器的根上运行WordPress(假设它没有被直接访问)。将私有服务器向下移动一个级别要稍微复杂一些,并且需要对两个服务器上的web服务器配置稍加修改。