问题描述
我有一个域名,比如www.domain.com。我已经开发了一个Java Web应用程序,说JWA。现在,我想用子域安装针对不同客户相同的应用程序,什么是最好的解决方案成为可能?
I've a domain, say www.domain.com. And I've developed a java web application, say jwa. Now I want to install the same app for different clients using subdomains, what is the best solution possible?
像client1.domain.com指向CLIENT1(已更名为JWA)
something like "client1.domain.com" points to "client1" (renamed jwa)
我知道我们能得到client1.domain.com/client1/但CLIENT1两次不好。或者至少我们可以得到client1.domain.com/jwa/,无有多个Tomcat实例?顺便说一句,我在同一台服务器上运行的Apache HTTP服务器,并使用proxy_module的Java / Tomcat的应用
I know we can get client1.domain.com/client1/ but client1 twice isn't good. or at least Can we get client1.domain.com/jwa/, without have multiple tomcat instances? btw, I'm running apache http server on the same server and using "proxy_module" for java/tomcat apps
问候
推荐答案
您不需要多个Tomcat实例 - 你可以点多个客户端跨多个子域使用相同的Web应用程序
You dont need multiple Tomcat instances - you can point multiple clients across multiple subdomains to use the same web app
但要确保这符合您的业务用例 - 即你实际的想要的web应用程序的多个实例的运行,还是可以的单个实例为所有客户。
BUT be sure that this fits with your business use case - i.e. do you actually want multiple instances of the webapp running, or a can single instance serve all your clients.
我指的是品牌/商标/共享数据/外观和手感等 - 是通用于所有的客户端
I'm referring to the branding/logo/shared data/look-and-feel etc - is that common across all clients?
让我们假设它是。
通过配置Apache的,正确的方法是使用虚拟主机
指令与mod_proxy的一起。
With an Apache configured, the right way is to use VirtualHost
directives along with mod_proxy.
在Apache的侧像这样的配置应该工作 - 创建每个子之一,并指出了的ProxyPass
和 ProxyPassReverse
到Tomcat Web应用程序
A configuration like this on the Apache side should work - create one per subdomain, and point the ProxyPass
and ProxyPassReverse
to the Tomcat web app
<VirtualHost *:80>
ServerName client1.domain.com
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /jwa http://client1.domain.com:8080/jwa
ProxyPassReverse /jwa http://client1.domain.com:8080/jwa
</VirtualHost>
相关阅读
Apache的文档
Apache docs have lots of examples of VirtualHost configuration
有也没有Apache的httpd的一个解决方案,可以server.xml中的Tomcat中配置主机entires但是Apache是一个更好的地方来管理您的域的网址
There is also a solution without Apache httpd, you can configure Host entires within Tomcat server.xml but Apache is a better place to manage your domain URLs
这篇关于URL重定向/同样的Java Web应用到多个子域映射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!