java 如果连接器端口是 8081,如何从 apache tomcat 中的 URL 中删除端口号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31584649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to remove port number from URL in apache tomcat if connector port is 8081
提问by Sushant Srivastava
I am running multiple instance of tomcat on my linux machine. so there are more than one connector ports for different instance like 8080,8081,8082. I want to remove port number from URL.
我在我的 linux 机器上运行多个 tomcat 实例。因此对于不同的实例,例如 8080,8081,8082,有多个连接器端口。我想从 URL 中删除端口号。
For example :-
Current url : -www.sushant.com:8081/
Needed :-www.sushant.com/
please suggest me how can i do this.
Thanks.
例如:-
当前网址:-www.sushant.com:8081/
需要:-www.sushant.com/
请建议我如何做到这一点。
谢谢。
回答by javahippie
You should consider using a proxy on your server. There is a really good tutorial at apache.org, using an Apache Web Server.
您应该考虑在您的服务器上使用代理。apache.org 上有一个非常好的教程,使用 Apache Web 服务器。
http://tomcat.apache.org/tomcat-7.0-doc/proxy-howto.html
http://tomcat.apache.org/tomcat-7.0-doc/proxy-howto.html
This enables you to connect to your server via port 80, which is not printed in the url bar of your browser.
这使您可以通过端口 80 连接到服务器,该端口不会打印在浏览器的 url 栏中。
回答by Darpan
I saw answer above and struggled a bit, so thought of putting up an example since I was on ubuntu, so I had to change apache2.conf
file in /etc/apache2/
You can find your apache2.conf
file or httpd.conf
as per your OS
我看到上面的答案并有点挣扎,所以想举个例子,因为我在 ubuntu 上,所以我不得不apache2.conf
在/etc/apache2/
你可以找到你的apache2.conf
文件或httpd.conf
根据你的操作系统更改文件
I added following rules -
我添加了以下规则 -
<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>
So, now it works both with and without the port.
所以,现在它可以在有和没有端口的情况下工作。