Apache 使用哪种方法设置动态端口映射器

Apache 使用哪种方法设置动态端口映射器,apache,networking,routing,tcp,mapping,Apache,Networking,Routing,Tcp,Mapping,我有一个web应用程序,它依赖于许多后端服务,我希望能够在这些服务的不同实例之间动态切换。因此,我们的想法是创建一个中间应用程序,它可以监听某些端口并根据需要重定向流量 如果我处理的是纯HTTP,我会考虑使用Apache和proxy_pass来实现这一点,这将是理想的(快速、可重新配置且无停机时间),但这不仅仅是HTTP流量,这也是我陷入困境的原因 任何朝着正确方向的轻推都将不胜感激 谢谢 Rob为什么不使用软件(如Vyatta、pfSense等)或硬件路由器,并在适当的位置设置一些NAT规则

我有一个web应用程序,它依赖于许多后端服务,我希望能够在这些服务的不同实例之间动态切换。因此,我们的想法是创建一个中间应用程序,它可以监听某些端口并根据需要重定向流量

如果我处理的是纯HTTP,我会考虑使用Apache和proxy_pass来实现这一点,这将是理想的(快速、可重新配置且无停机时间),但这不仅仅是HTTP流量,这也是我陷入困境的原因

任何朝着正确方向的轻推都将不胜感激

谢谢


Rob

为什么不使用软件(如Vyatta、pfSense等)或硬件路由器,并在适当的位置设置一些NAT规则


当我需要快速转发一些端口等时,我有时会使用一个非常整洁的开源应用程序。要做一些测试,请使用TcpTunnel:

您可以将Apache配置为动态侦听一组端口(在我的系统中似乎有上限,大约100个),然后使用mod_rewrite将这些端口动态映射到您的内容。您还可以使用用Perl编写的动态主机,但是您还需要包括所有其他配置,这些配置对于每个实例都是相同的

# Use Perl to write out many Listen directives
LoadModule perl_module  libexec/apache2/mod_perl.so

<Perl>

  # The Dynamic Ports are those from 49152 through 65535
  # On the machines I tested 100 seems to be the upper limit
  # Apache 2 seems to have issues starting (memory?) when the number
  # is too high. Once the server has started, there does not seem
  # to be a performance hit for having a large number of ports open

  # Starting at 50000 for cleanliness
  my $lower_port = 50000;
  my $max_ports_to_use = 100;


  my $upper_port = $lower_port + $max_ports_to_use;

  foreach my $port ($lower_port .. $upper_port) {

    # Listen on a specific port number
    push @Listen, $port;

  };

</Perl>


# if we are in the range of dynamic ports
RewriteEngine on
RewriteCond %{SERVER_PORT} >49152
RewriteCond %{SERVER_PORT} <65535
  # serve up content on that port number
  RewriteRule (.*) /dynamic_sites/%{SERVER_PORT}/$1
#使用Perl编写许多Listen指令
LoadModule perl_module libexec/apache2/mod_perl.so
#动态端口是从49152到65535的端口
#在我测试的机器上,100似乎是上限
#Apache2似乎在启动时(内存?)出现问题
#太高了。一旦服务器启动,就不会出现任何问题
#因为打开了大量端口而受到性能打击
#清洁度从50000开始
我的$lower\u端口=50000;
我的$max_port_to_use=100;
my$upper_port=$lower_port+$max_ports_to_use;
foreach my$端口($lower_port..$upper_port){
#侦听特定端口号
按@Listen$port;
};
#如果我们在动态端口范围内
重新启动发动机
重写cond%{SERVER_PORT}>49152

RewriteCond%{SERVER_PORT}正如我提到的,你可以使用像Vyatta这样的自由软件路由器,并在虚拟机上运行它,这不会花费你任何东西,而且需要一个小时来设置。或者,您可以轻松编写TcpTunnel脚本,以更改端口转发等。