假设我在每种可想到的技术上都有多个 http 服务器。例如用于 PHP 的 Apache、用于 JSP 的 Tomcat 等等......在一台机器上运行,具有一个物理接口(interface)和一个公共(public) IP。
现在,我希望它们都在同一个端口上响应,当然是 80。这是不可能的,因为一个应用程序 = 一个使用 TCP/IP 的端口。我知道,例如 apache 可以集成 Tomcat,并处理 .jsp 页面上的请求给他,但我正在考虑不同的、更通用的方法。
这是可能的,也许更好的问题是,是否有任何应用程序可以预过滤 http 请求并将它们转发到不同的端口?基于请求的域?双向?所以客户会认为他正在与端口 80 通话,但在内部他会由运行在端口 8080 上的 Tomcat 提供服务?我希望你明白我的意思。
谢谢。
最佳答案
我会使用反向代理,例如 apache mod_proxy。反向代理将传入请求重新路由到正确的服务器,即使所有服务器都在同一台物理主机上。
Reverse proxies can be used whenever multiple web servers must be accessible via a single public IP address. The web servers listen on different ports in the same machine, with the same local IP address or, possibly, on different machines and different local IP addresses altogether. The reverse proxy analyses each incoming call and delivers it to the right server within the local area network.
关于apache - 基于完整域名重新路由http请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9296769/