我在路由器后面有 webserver1,当前为 mydomain.com 提供所有 http 流量。我刚刚添加了 webserver2,并希望将 mydomain.com/server2 流量重定向到该框。对于用户来说,重定向应该不会被注意到(即 URL 应该只是 mydomain.com/server2,并且重定向发生在幕后)。我如何在 webserver1 的 apache 配置中设置它(我假设 webserver2 的配置不需要做任何特别的事情)?
我已经尝试了这里给出的建议,使用 mod_rewrite,但它似乎没有成功:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/server2/
RewriteRule ^/$ http://192.168.1.102/ [P,L]
Run Code Online (Sandbox Code Playgroud)
如果相关,webserver1 正在使用 mod_wsgi 托管一个 django 应用程序,还有一些其他应用程序被重定向。这是虚拟主机配置:
<VirtualHost *:80>
ServerAdmin admin@mydomain.com
ServerName www.mydomain.com
ServerAlias 127.0.0.1
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/server2/
RewriteRule ^/$ http://192.168.1.102 [P,L]
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ …Run Code Online (Sandbox Code Playgroud)