【问题标题】:how to remove port number from URL in apache tomcat if connector port is 8081如果连接器端口是 8081,如何从 apache tomcat 中的 URL 中删除端口号
【发布时间】:2025-12-28 16:05:06
【问题描述】:

我在我的 linux 机器上运行多个 tomcat 实例。因此,对于不同的实例,例如 8080,8081,8082,有多个连接器端口。我想从 URL 中删除端口号。

例如:-
当前网址:- www.sushant.com:8081/
需要:-www.sushant.com/
请建议我该怎么做。
谢谢。

【问题讨论】:

  • 我使用了 80 端口,但通过使用它,我只能从我将端口配置为 80 的单个实例中删除端口。但正如我提到的,有许多不同的端口。
  • 您需要一个在反向代理模式下运行的前端服务器,它将外部 URL 映射到内部 URL,例如将 www.sushant.com/service1 映射到 www.sushant.com:8081。谷歌nginx reverse proxy

标签: java tomcat port


【解决方案1】:

您应该考虑在您的服务器上使用代理。 apache.org 上有一个非常好的教程,使用 Apache Web 服务器。

http://tomcat.apache.org/tomcat-7.0-doc/proxy-howto.html

这使您可以通过端口 80 连接到您的服务器,该端口未显示在浏览器的 url 栏中。

【讨论】:

    【解决方案2】:

    我看到上面的答案有点挣扎,所以想举个例子,因为我在ubuntu上,所以我不得不在/etc/apache2/中更改apache2.conf文件 您可以根据您的操作系统找到您的 apache2.conf 文件或 httpd.conf

    我添加了以下规则 -

        <VirtualHost *:80>  
        ServerName sushant.com
        ServerAlias www.sushant.com
    
        ProxyRequests On
    
        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>
    
        <Location />
                ProxyPass http://localhost:7777/
                ProxyPassReverse http://localhost:7777/
        </Location>
    
     </VirtualHost>
     <VirtualHost *:8081>
        ServerName  sushant.com
        ServerAlias www.sushant.com
    
        ProxyRequests on
    
        <Proxy *>
                Order deny,allow
                Allow from all
        </Proxy>
    
        <Location />
                ProxyPass http://localhost:8081/
                ProxyPassReverse http://localhost:8081/
        </Location>
    
      </VirtualHost>
    

    所以,现在它可以在有和没有端口的情况下使用。

    【讨论】: