简体   繁体   English

如何为 Spring Boot 应用程序配置嵌入式 Tomcat 虚拟主机?

[英]how to configure Embedded Tomcat virtual host for Spring Boot Application?

i have a multiple domains on my centos vps (domains running on apache http server via virtual host configurations).我的 centos vps 上有多个域(通过虚拟主机配置在 apache http 服务器上运行的域)。 and also same vps, i want to add my new domain but that domain will route my spring boot application (application is a jar file also inside embedded tomcat ).还有相同的 vps,我想添加我的新域,但该域将路由我的 spring boot 应用程序(应用程序是一个 jar 文件,也在嵌入式 tomcat 中)。 i couldn't find any configuration for embedded tomcat specific domains and ports.我找不到嵌入式 tomcat 特定域和端口的任何配置。

standalone Tomcat i can make configuration via server.xml file like this image独立的 Tomcat 我可以通过 server.xml 文件进行配置,如下图

also this short tutorial shows configuration for stadalone tomcat Tomcat Virtual Host Configuration这个简短的教程还显示了 stadalone tomcat Tomcat 虚拟主机配置的配置

But how can i do that configuration for embedded Tomcat ?但是我怎样才能为嵌入式 Tomcat 进行配置呢? Any suggestion ?有什么建议吗?

With Spring Boot embedded Tomcat, you are hosting only one application per servlet container. 使用Spring Boot嵌入式Tomcat,每个servlet容器只能托管一个应用程序。 So I don't believe that Tomcat's concept of Virtual Hosts make sense at all. 所以我不相信Tomcat的虚拟主机概念是有意义的。

If you have to host your app on shared Tomcat instance, just build WAR without embedded container. 如果您必须在共享Tomcat实例上托管您的应用程序,只需构建没有嵌入式容器的WAR。

It depends.这取决于。 2 ways to deploy your project.jar as you want to :根据需要部署project.jar的 2 种方法:

First way : You can use the "apache web server" and his own "mod_proxy" in order to serve as many Spring webapps you want to, each on a specific port configured with "php-fpm" and with a proxy defined to route requests from/to your namebased VirtualHost configuration.第一种方式:您可以使用“apache web server”和他自己的“mod_proxy”,以便为您想要的任意数量的 Spring webapps 提供服务,每个 webapps 都在一个配置有“php-fpm”的特定端口上,并且定义了一个代理来路由请求从/到您的基于名称的 VirtualHost 配置。

Nowadays, with Spring Boot 2.5 , all you have to do is to set the property server.port in your application.properties file, and use it accordingly with mod_proxy directives.如今,使用 Spring Boot 2.5 ,您所要做的就是在application.properties文件中设置属性server.port ,并相应地使用mod_proxy指令。 If you are using profile, you can either set one port to dev or prod or test or whatever properties file you need.如果您使用配置文件,您可以将一个端口设置为devprodtest或您需要的任何属性文件。

Another way to proceed : you can use the apache web server "mod_jk" bridge module to configure multiple load-balancers for your Virtualhosts too.另一种方法:您也可以使用 apache Web 服务器“mod_jk”桥模块为您的虚拟主机配置多个负载平衡器。

Choose your path, young Jedi ;)选择你的道路,年轻的绝地;)

This response is certainly not for the OP, 7 years later, but for other people whom are using any web search engine like Google.这种回应当然不是针对 7 年后的 OP,而是针对使用任何网络搜索引擎(如 Google)的其他人。 They will come here and see "something is impossible".他们会来到这里,看到“有些事情是不可能的”。 It is not true.这不是真的。

暂无
暂无

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

相关问题 使用application.yml在Spring Boot中配置嵌入式Tomcat的日志记录 - Use application.yml to configure logging of embedded Tomcat in Spring Boot 如何为嵌入在我的 spring-boot 应用程序中的 Web 服务器(Tomcat)配置低级套接字属性? - How to configure low-level socket properties for a web server (Tomcat) embedded in my spring-boot application? 如何使用Spring Boot和嵌入式Tomcat配置此属性? - How do I configure this property with Spring Boot and an embedded Tomcat? 如何在 spring boot 应用程序中检查嵌入式 tomcat 的健康状况? - How to check the health of embedded tomcat in spring boot application? 如何在没有嵌入式tomcat的情况下启动Spring Boot应用程序? - How do I launch a Spring Boot application without the embedded tomcat? 如何在Spring启动应用程序中将用户添加到嵌入式tomcat? - How to add a user to an embedded tomcat in a spring boot application? 如何使用Spring Boot应用程序更改嵌入式tomcat连接器端口 - How to change embedded tomcat connector port using spring boot application Spring Boot应用程序未启动嵌入式Tomcat - Spring boot application not starting embedded tomcat Spring Boot - 嵌入式 Tomcat - Spring boot - Embedded Tomcat 如何配置使用 tomcat 并依赖于另一个应用程序的 Spring Boot 应用程序使用 tomcat - How to configure a Spring Boot Application that uses tomcat and has a dependency to another Application uses tomcat
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM