微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决将请求代理到子文件夹时,无法在 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/

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。