如何配置apache2子域以路由到不同的服务器
问题描述:
我正在运行apache 2.4.7,目前我的所有流量都将转到同一服务器/实例上的8080上的后端服务器。如何配置apache2子域以路由到不同的服务器
我希望我的WWW流量去一个新的服务器/实例和我的所有其他子域(应用程序,API等)去到现有的8080
有人可以提供一些方向?
帮助赞赏。
<VirtualHost *:80>
ProxyPreserveHost On
ServerAdmin [email protected]
ServerName example.com
Redirect "/" "https://www.example.com/"
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html/
Redirect "/ft/" "/"
ErrorLog /var/www/example.com/logs/error.log
CustomLog /var/www/example.com/logs/access.log combined
ProxyPass/http://0.0.0.0:8080/
ProxyPassReverse/http://0.0.0.0:8080/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
答
如果你想要做一个外部重定向为www
子域的新服务器,您需要将以下添加到您的配置,在其他重写规则:
RewriteCond ${HTTP_HOST} ^www\. [NC]
RewriteRule^https://www.example.com/${REQUEST_URI} [L,R=301]
而你需要删除ServerAlias
指令。这也假设你已经将DNS指向新的主机。
如果服务于www
内容的新的框是另一种支持的服务器,你就需要另一个虚拟主机。在顶部添加以下代码:
<VirtualHost *:80>
ServerName www.example.com
ProxyPass/http://other-box/
ProxyPassReverse/http://other-box/
</VirtualHost>
而且您仍然需要删除ServerAlias
指令。