Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set Domain name in Spring Boot App with embedded tomcat

I am developing a application in spring boot with embedded tomcat. In my local which runs on a port 8080 and i can give url http://locahost:8080. How can change this to my domain? like www.mydomain.com which should work similar to localhost. How to configure this? I am using embedded tomacat not externally installed tomcat server.

like image 251
Nikesh Kedlaya Avatar asked Sep 25 '17 06:09

Nikesh Kedlaya


People also ask

How do I add a domain to spring boot?

First of all you need to have a domain registered. Then you need to have a Machine in premise or in the Cloud whose Public IP address is mapped to the domain you registered, and that has the correct port (80) opened. Then you need to start your Spring boot application to run on port 80 not 8080.

Can we configure embedded Tomcat server in spring boot?

Overview. Spring Boot ships with an Embedded Tomcat Server. When we run a Spring Boot Application, the embedded tomcat server is started and the application is launched inside the server. The Embedded tomcat server has a set of default configurations, which makes them ready to use.

How does spring boot embedded Tomcat work?

Spring Boot is a popular Java-based framework to develop microservices. By default, the Spring Tool Suite (STS) IDE -- which is used to build a Spring Boot application -- will automatically create an embedded Tomcat server with the microservices developed each time a build or deployment occurs.


2 Answers

First of all you need to have a domain registered.

Then you need to have a Machine in premise or in the Cloud whose Public IP address is mapped to the domain you registered, and that has the correct port (80) opened.

Then you need to start your Spring boot application to run on port 80 not 8080. You can do that by using CLI argument --server.port=80 or adding server.port=80 in application.properties file or application.yaml file.

like image 81
shazin Avatar answered Sep 23 '22 12:09

shazin


If you are deploying this spring boot application as your primary service and not running it on a server that has Apache Web Server already installed, you can manually set the port 80, which is for HTTP requests. 443 is encrypted and thus HTTPS. You can set these settings on your firewall of your server.

However, if this Spring boot app happens to be something like an API, where it's just endpoints you want to hit from a website that you have on your server (running on something like an Apache Web Server), you're going to need to setup up a reverse proxy or else they will both be trying to use port 80:

https://medium.com/@codebyamir/using-apache-as-a-reverse-proxy-for-spring-boot-embedded-tomcat-f704da73e7c8

So you should leave the port as 8080 on the Spring app (running the embedded tomcat server), and your Apache Web Server should be using port 80 for say , your website at www.mydomain.com.

Thus, the proxy will redirect incoming HTTP requests to your Tomcat service at port 8080 and thus the endpoints will be triggered via www.mydomain.com/api-end-point-here

like image 36
ennth Avatar answered Sep 26 '22 12:09

ennth