将部分流量重定向到其他服务器
Redirect a part of traffic to other server
在我的服务器上,我想通过以下方式重定向通过端口 80 访问的所有流量:
http://12.34.56.78/blahblah/...
到 Python 网络服务器,例如监听端口 7777...
... 并使用 Apache /home/www/
保留所有其余部分 http://12.34.56.78/(anythingelse)/... /home/www/
。
访问 http://12.34.56.78/blahblah/ 时,我得到:
Internal Server Error
The server encountered an internal error or misconfiguration and
was unable to complete your request.
为什么它不能与以下 Apache 配置一起使用?
<VirtualHost *:80>
ServerName 12.34.56.78
DocumentRoot /home/www/
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName 12.34.56.78
<Directory /blahblah/>
RewriteEngine On
RewriteRule /(.*) localhost:7777/ [P,L]
</Directory>
</VirtualHost>
问题很简单,您使用的是第二个虚拟主机 mod_rewrite。
RewriteRule 的工作方式是您在 URL 中指定要匹配的路径,然后它会重写为其他内容(在本例中为代理)。
此外,目录元素是指主机上的特定真实目录。根据您的问题,您似乎不希望将 RewriteRules 放在 Directory 元素中。
此外,您应该在代理的 RewriteRule 中指定 URL 方案。
按照这些思路应该可行。
<VirtualHost *:80>
ServerName 12.34.56.78
DocumentRoot /home/www/
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
RewriteEngine On
RewriteRule ^/blahblah(.*)$ http://localhost:7777 [P,L]
</VirtualHost>
在我的服务器上,我想通过以下方式重定向通过端口 80 访问的所有流量:
http://12.34.56.78/blahblah/...
到 Python 网络服务器,例如监听端口 7777...
... 并使用 Apache /home/www/
保留所有其余部分 http://12.34.56.78/(anythingelse)/... /home/www/
。
访问 http://12.34.56.78/blahblah/ 时,我得到:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
为什么它不能与以下 Apache 配置一起使用?
<VirtualHost *:80>
ServerName 12.34.56.78
DocumentRoot /home/www/
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName 12.34.56.78
<Directory /blahblah/>
RewriteEngine On
RewriteRule /(.*) localhost:7777/ [P,L]
</Directory>
</VirtualHost>
问题很简单,您使用的是第二个虚拟主机 mod_rewrite。
RewriteRule 的工作方式是您在 URL 中指定要匹配的路径,然后它会重写为其他内容(在本例中为代理)。
此外,目录元素是指主机上的特定真实目录。根据您的问题,您似乎不希望将 RewriteRules 放在 Directory 元素中。
此外,您应该在代理的 RewriteRule 中指定 URL 方案。
按照这些思路应该可行。
<VirtualHost *:80>
ServerName 12.34.56.78
DocumentRoot /home/www/
<Directory />
Options FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
RewriteEngine On
RewriteRule ^/blahblah(.*)$ http://localhost:7777 [P,L]
</VirtualHost>