繁体   English   中英

Tomcat上的多租户

[英]Multi-tenancy on tomcat

我已经设置了在Tomcat上公开和实现的JSON API。 我想使用以下URL方法在Tomcat上为这些API实现多租户:

companyname1.domain.com/api/getUsers...
companyname2.domain.com/api/getUsers...
companyname3.domain.com/api/getUsers...

让我知道是否有使用上下文或其他机制实现它的最佳实践。 我不想为每个公司创建一个单独的Tomcat实例。 此外,公司注册后,可以通过任何方式动态创建它。

预先感谢您,Moshe

可以使用向Tomcat Web应用程序提供不同参数的多个反向代理来完成。 最简单的设置(使用Apache HTTP和mod_proxy_ajp )可能是保留原始请求的主机并在Web应用程序内部对其进行解析。

<VirtualHost *:80>
    ServerName companyname1.domain.com

    ProxyPass / ajp://localhost:8009/
    ProxyPassReverse / ajp://localhost:8009/
    ProxyPreserveHost On
</VirtualHost>

<VirtualHost *:80>
    ServerName companyname2.domain.com

    ProxyPass /api ajp://localhost:8009/
    ProxyPassReverse / ajp://localhost:8009/
    ProxyPreserveHost On
</VirtualHost>

<VirtualHost *:80>
    ServerName companyname3.domain.com

    ProxyPass / ajp://localhost:8009/
    ProxyPassReverse / ajp://localhost:8009/
    ProxyPreserveHost On
</VirtualHost>

在Tomcats server.xml中创建多个虚拟主机 ,以侦听您的域。 这些应该指向不同的webapps目录 ,将您的特定应用程序托管在ROOT目录中:

<Host name="localhost" appBase="domain1-webapps" autoDeploy="true" unpackWARs="true"></Host>
<Host name="companyname1.domain.com" appBase="domain1-webapps" autoDeploy="true" unpackWARs="true"></Host>
<Host name="companyname2.domain.com" appBase="domain2-webapps" autoDeploy="true" unpackWARs="true"></Host>
...
I can not comment because of my reputation is below than 50.

if URI is same like 
companyname1.domain.com/api/getUsers
companyname2.domain.com/api/getUsers
companyname3.domain.com/api/getUsers

then Apache web server found domain companyname1.domain.com and from httpd file, it send call to tomcat application server through AJP connector. But problem is that how can it found which war file to run. 

因此,URL中需要应用程序名称

companyname1.domain.com/abc/api/getUsers
companyname2.domain.com/xyz/api/getUsers
companyname3.domain.com/fgf/api/getUsers
We can use server context setting. like as per tomcat server specification. 
The Host element represents a virtual host, which is an association of a network name for a server (such as "www.mycompany.com") with the particular server on which Tomcat is running. For clients to be able to connect to a Tomcat server using its network name, this name must be registered in the Domain Name Service (DNS) server that manages the Internet domain you belong to - contact your Network Administrator for more information.

In many cases, System Administrators wish to associate more than one network name (such as www.mycompany.com and company.com) with the same virtual host and applications. This can be accomplished using the Host Name Aliases feature discussed below.

One or more Host elements are nested inside an Engine element. Inside the Host element, you can nest Context elements for the web applications associated with this virtual host. Exactly one of the Hosts associated with each Engine MUST have a name matching the defaultHost attribute of that Engine.

Clients normally use host names to identify the server they wish to connect to. This host name is also included in the HTTP request headers. Tomcat extracts the host name from the HTTP headers and looks for a Host with a matching name. If no match is found, the request is routed to the default host. The name of the default host does not have to match a DNS name (although it can) since any request where the DNS name does not match the name of a Host element will be routed to the default host.

有关详细信息。 通过此链接。 https : //tomcat.apache.org/tomcat-8.0-doc/config/host.html

暂无
暂无

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

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