将请求代理到子文件夹时,无法在 wordpress 中使用自定义永久链接

问题描述

我们有一个设置,其中一个站点位于一个 (aws) 服务器上,例如 www.example.com。然后我们在 /blog 子目录 www.example.com/blog

中的另一个 aws 服务器上运行一个 wordpress 博客

在主服务器上,我们使用 apache 将 /blog 请求代理到另一台服务器,例如:

<VirtualHost *:443>
...
ProxyPass /blog/ https://xx.xxx.x.xxx/siteA/
ProxyPassReverse /blog/ https://xx.xxx.x.xxx/siteA/
ProxyPass /blog https://xx.xxx.x.xxx/siteA/
ProxyPassReverse /blog https://xx.xxx.x.xxx/siteA/
...
</VirtualHost>

这有效并且博客显示......但前提是永久链接设置为“普通”。如果我们将它们设置为其他任何内容,那么我们只会收到 404 响应。

更复杂的是,博客服务器在以下结构中保存了许多不同的博客

  • /var/www/blog/siteA
  • /var/www/blog/siteB
  • /var/www/blog/siteC

博客服务器上的虚拟主机设置为:

<VirtualHost *:443>
...
DocumentRoot /var/www/blog
<Directory "/var/www/blog/siteA/">
Options Indexes FollowSymLinks
AllowOverride all
Order allow,deny
allow from all
Require all granted
</Directory>
...
</VirtualHost>

博客上的 .htaccess 文件是:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.PHP$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.PHP [L]
</IfModule>

我已经尝试了重写基础和虚拟主机设置的各种组合,但我似乎无处可去 - 那些自定义永久链接永远不起作用。

解决方法

以防其他人偶然发现同一问题。我尝试更改权限,但即使 777 也不起作用。

最后的解决方案是将“ProxyPreserveHost On”添加到主服务器上的虚拟主机,并在代理上包含“blog”子文件夹:

<VirtualHost *:443>
ProxyPreserveHost On
ProxyPass /blog/ https://xx.xxx.x.xxx/siteA/blog/
ProxyPassReverse /blog/ https://xx.xxx.x.xxx/siteA/blog/
ProxyPass /blog https://xx.xxx.x.xxx/siteA/blog/
ProxyPassReverse /blog https://xx.xxx.x.xxx/siteA/blog/