暴露不在端口80上侦听的Web服务器

时间:2014-12-03 17:23:15

标签: web port server

我的问题可能是微不足道的,并且是重复的,但要么我不能制定它,要么它还没有得到回答。

我在Digital Ocean Droplet上有两个网络服务器。一个是侦听端口80,可以通过example.com访问(DNS在路由53上),另一个在端口8080上访问:如何从{{1}访问它}}?

我想我正在寻找的软件会拦截HTTP请求,检查引用来源,并将来自example-2.com的端口example.com和来自80的端口路由到端口{} example-2.com。它是什么?

1 个答案:

答案 0 :(得分:1)

仅使用DNS无法完成此操作。默认情况下,当网址以" http"开头时,网络浏览器会尝试连接到端口80。没有指定端口。用户必须知道连接到端口8080并显式访问URL

http://example-2.com:8080

我假设您在相同的操作系统环境/ IP地址上运行两个Web服务器实例,尽管这也适用于单独的托管环境。您可能需要的是反向Web代理,它可以检查所请求的域名并路由到适当的服务器实例。您将在端口80上运行反向Web代理,并可能将您当前在端口80上运行的服务器移动到另一个端口(例如,8081)。

使用mod_proxy的Apache和虚拟主机设置是一种可能的解决方案。假设example.com和example-2.com指向Apache实例,请将其配置为:

<VirtualHost *:80>
 ServerName example.com
     ServerAdmin webmaster@example.com

     ProxyRequests off
     ProxyPreserveHost on
     ProxyPass / http://localhost:8081/
     ProxyPassReverse / http://localhost:8081/
     <Proxy *>
          Order allow,deny
          Allow from all
     </Proxy>
</VirtualHost>

<VirtualHost *:80>
     ServerName example-2.com
     ServerAdmin webmaster@example-2.com

     ProxyRequests off
     ProxyPreserveHost on
     ProxyPass / http://localhost:8080/
     ProxyPassReverse / http://localhost:8080/
     <Proxy *>
          Order allow,deny
          Allow from all
     </Proxy>
</VirtualHost>