我有一个通过 ProxyPass 为我的应用程序提供服务的虚拟主机,它运行良好。现在我想使用“/en”路由下的简单 Wordpress 提供我的服务的英文版。假设 Wordpress 位于“home/path/to/wp”,我该如何实现呢?这是我在 /etc/apache2/sites-enabled/ 下的当前配置:
<VirtualHost xx.xx.xx.xx:443>
ServerName xx.com
ServerAlias www.xx.com
SSLEngine on
.
.
.
ProxyPass /en !
<Directory home/path/to/wp>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
#DocumentRoot "home/path/to/wp"
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php
AddType application/x-httpd-php7.2 .php7.2
</Directory>
Redirect /en home/path/to/wp
ProxyPass / http://0.0.0.0:3000/
ProxyPassReverse / http://0.0.0.0:3000/
#RewriteEngine on
#RewriteRule ^/en/(.*)$ /home/kerman/public_html [L,PT]
#Alias /en /home/kerman/public_html
</VirtualHost>
正如您在代码中看到的,我已经尝试过Redirect
,Alias
但Rewrite
它们都无法正常工作。
针对这种情况的实际解决方法是什么?
答案1
您已尝试了所有方法,但没有一种方法能够完全按照文档进行。
首先,您的文件系统路径必须是从根目录开始的绝对路径/
。您的问题中现在有很多路径,但为了简单起见,我们假设您的 WordPress 路径是/home/kerman/public_html/en
,其他所有内容都代理到后端:3000
。(#Comments 现在用作评论。)
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
SSLEngine on
# and here the keys & co.
DocumentRoot /home/kerman/public_html
# /en under the DocumentRoot i.e. /home/kerman/public_html/en
# This must be before the ProxyPass for /
ProxyPass /en !
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000/
<Directory /home/kerman/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
# All is All already: no need for a list
AllowOverride All
# Allow is deprecated, and this already does it
Require all granted
</Directory>
</VirtualHost>
无需解决方法。