[英]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.如果您使用配置文件,您可以将一个端口设置为
dev
或prod
或test
或您需要的任何属性文件。
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.