如何在apache / nginx中为Spring Boot多租户应用程序创建反向代理

问题描述 投票:1回答:1

我需要在春季启动时为多租户应用创建POC,该POC已经准备就绪。我需要配置代理以将租户名称传递给tomcat应用服务器。此名称用于区分租户。默认租户是app。租户名称是动态的。这类似于Shopify所做的操作,其中每个商店名称均为storename.shopify.com。

例如,对于app1.example.com。代理应将app1转发给spring,用于app2.example.com;代理应该将app2转发给spring吗?

java spring-boot reverse-proxy multi-tenant nginx-reverse-proxy
1个回答
0
投票

指向运行中的springboot应用程序的简单反向代理配置即可解决。在我的spring应用程序中,我检索标题信息以显示每个租户的信息。

反向代理配置

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName www.mydomain.com
    #ServerAlias *.mydomain.com


    ProxyPreserveHost  On
    ProxyPass  / http://127.0.0.1:8082/
    ProxyPassReverse  / http://127.0.0.1:8082

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

用于获取服务器信息的Spring Boot Config

String schemeName = httpServletRequest.getScheme();     
String serverName = httpServletRequest.getServerName();
© www.soinside.com 2019 - 2024. All rights reserved.