How set up Spring Boot to run HTTPS / HTTP ports
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Introduction
Spring Boot can serve HTTPS directly, but only one embedded server connector is configured from properties by default. If you want the application to listen on both HTTPS and HTTP ports at the same time, the usual pattern is to configure HTTPS as the main connector and then add a second HTTP connector programmatically. For many production systems, a reverse proxy is even simpler, but it is still useful to know how to do it inside the app.
Configure HTTPS as the Main Connector
Start by configuring SSL in application.properties or application.yml. This makes the embedded server listen on the secure port.
With this setup alone, your app serves HTTPS on port 8443.
You can create a local test certificate with keytool:
That gives Spring Boot the keystore it needs for TLS termination.
Add a Second HTTP Connector in Tomcat
There is no built-in property such as server.http.port that automatically adds a second connector. For embedded Tomcat, you add the extra connector yourself.
After this:
- '
https://localhost:8443serves HTTPS' - '
http://localhost:8080is available as a plain HTTP connector'
The redirectPort tells Tomcat where secure traffic should go if security constraints trigger a redirect.
Redirect HTTP Traffic to HTTPS
If the goal is "accept both ports, but force browsers onto HTTPS," configure your security rules to require secure requests.
In modern Spring Security:
That way, the HTTP connector can exist for compatibility or redirection, while real application traffic ends up on HTTPS.
When a Reverse Proxy Is Better
Running both connectors inside the app is valid, but it is not always the best architecture. In many deployments, a reverse proxy or load balancer handles TLS and forwards traffic to a single internal HTTP port.
That approach is often better when you need:
- centralized certificate management
- HTTP to HTTPS redirects outside the JVM
- consistent edge security across several services
So the embedded dual-port setup is useful, but not automatically the production default.
Common Pitfalls
One common mistake is inventing a property such as server.port.https or server.http.port. Spring Boot does not auto-wire a second connector from those names.
Another issue is forgetting that the connector example above is Tomcat-specific. If your app uses Jetty or Undertow, the code changes because the server implementation is different.
Keystore errors are also frequent. If the file path, password, or alias is wrong, the app may fail at startup before the HTTP connector logic even matters.
Finally, do not assume redirectPort alone forces all traffic to HTTPS. Redirection also depends on security configuration and request handling.
Summary
- Spring Boot config properties usually define one embedded server connector.
- Configure HTTPS as the primary connector with SSL properties.
- Add a second HTTP connector programmatically for embedded Tomcat.
- Use Spring Security if you want HTTP requests redirected to HTTPS.
- In many production systems, handling TLS and redirects in a reverse proxy is simpler than dual-port app configuration.
Related reading
- how sockets or communication channels are maintained in distibuted system
- How to access a Tensorflow docker instance from the outside without Jupyter - for distributed Tensorflow
- How to access entity manager with spring boot and spring data
- How to access host port from docker container
- How should I resolve --secure-file-priv in MySQL?
- How to access RabbitMq publicly
- How should I copy Strings in Java?
- How should I map long to int in hashCode?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.