简体   繁体   English

如何配置Apache以将子域重定向到Tomcat应用程序

[英]How to configure Apache to redirect subdomains to Tomcat applications

I have a few applications hosted on Tomcat running a machine called test-websites throuhg port 8080. So they are accessible like this: 我在Tomcat上托管了一些应用程序,它们通过8080端口运行一台名为test-websites的计算机。因此可以通过以下方式访问它们:

http://test-websites:8080/app1/
http://test-websites:8080/app2/
...
http://test-websites:8080/appN/

What I need to do is make these applications accessible on my local network by: 我需要做的是通过以下方式使这些应用程序可在本地网络上访问:

http://app1.test-websites/
http://app2.test-websites/
...
http://appN.test-websites/

As I add new applications to Tomcat's webapps folder, I want them to be automatically available using the same subdomain pattern. 当我将新应用程序添加到Tomcat的webapps文件夹时,我希望它们可以使用相同的子域模式自动使用。

So I thought using Apache in front of Tomcat to make the URL rewriting would be a good idea, but so far I have not been able to configure the virtual host on Apache to make this redirect. 因此,我认为在Tomcat之前使用Apache进行URL重写将是一个好主意,但是到目前为止,我还无法在Apache上配置虚拟主机来进行此重定向。 I installed apache2 on port 80 and I see the default "It Works!" 我在端口80上安装了apache2,然后看到默认的“ It Works!”。 apache page when I access http://test-websites/ , but I couldn't find how to make the redirects to the apps in the Tomcat following the format above. 访问http://test-websites/时的apache页面,但是我找不到按照上述格式重定向到Tomcat中应用程序的方法。

I have searched for over 4 hours and didn't get an answer for this use case.. any help us much appreciated! 我已经搜索了4个多小时,但没有获得此用例的答案。任何帮助我们都非常感谢!

Thank you! 谢谢! Eduardo 爱德华多

First you need to add a DNS entry for app1.test-websites, app2.test-websites,.. such that it points to test-websites. 首先,您需要为app1.test-websites,app2.test-websites ..添加一个DNS条目,以便它指向测试网站。 Generally CNAME entry works best in this case. 通常,在这种情况下,CNAME条目效果最佳。 If you only need the URLs to resolve on your local machine (for testing purpose), you can just update your /etc/hosts or C:\\windows\\system32\\drivers\\etc\\hosts file. 如果仅需要URL在本地计算机上解析(出于测试目的),则只需更新/etc/hostsC:\\windows\\system32\\drivers\\etc\\hosts文件。 Otherwise you need to figure out how your company's network is setup and change the DNS entry (if it's a Windows domain network, normally there's a DNS service on the domain controller. On some smaller network you have to configure it on the router). 否则,您需要弄清楚公司网络的设置方式并更改DNS条目(如果是Windows域网络,则通常在域控制器上有DNS服务。在一些较小的网络上,您必须在路由器上进行配置)。

Next, the quickest way to achieve this is to not use apache2 to front it, bust simply have tomcat listening on port 80. You can setup virtual host on tomcat such that it serves different web-app depending on the URL requested . 接下来,实现此目标的最快方法是不使用apache2来实现它,只需让tomcat监听端口80就可以了。您可以在tomcat上设置虚拟主机,以便根据请求的URL为不同的Web应用提供服务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM