2

I ran into an issue with one of our Spring Boot applications. We have it running with https on port 8443 and it all works fine. Now we're building an integration with an external payment processor and they require that we have a callback endpoint in our application on port 443.

Some research tells me that deploying a Spring boot app listening to a port number below 1024 is not allowed. The threads i find on this issue usually say "use a port number above 1024" and the poster walks off happy. I already have that and need to figure out a solution that uses port 443.

Does anyone have any recommendations? Could i solve this by building an Apache proxy for the callback endpoint?

We have web applications using Apache2 and port 443 on the same server, so the Boot application needs to coexist with that.

Mats Andersson
  • 397
  • 2
  • 7
  • 21

2 Answers2

2

OK, i managed to solve this issue by myself in a pretty simple and elegant way. In the process, i also solved the issue of Spring boot applications having to be called with a port number in the URL, which has been annoying me.

I found this thread: Spring Boot with embedded Tomcat behind Apache proxy

In it, the solution is pretty much laid out. I had to activate three apache2 mods:

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod headers

I added these lines to my Apache2 vhost config file, right under ServerName in the VirtualHost tag:

SSLProxyEngine on
ProxyPass / https://127.0.0.1:8443/
ProxyPassReverse / https://127.0.0.1:8443/
RequestHeader set X-Forwarded-Proto https
RequestHeader set X-Forwarded-Port 443
ProxyPreserveHost On

8443 is the port number used by the Spring Boot application, as configured in the server.port property.

As a bonus, this also means we no longer need to open the ports used by our Boot applications in our firewall.

Mats Andersson
  • 397
  • 2
  • 7
  • 21
0

There several Web-Server or Reverse-Proxy solutions, which can listen on port 443 and route your requests to Port 8443 of your Spring Boot application server.

Beside Apache2 there are:

There are probably many more, but those 3 I used so far.

If your application is running in a cloud - the cloud provider offers typically also services, which can do this job, e.g. AWS ELB.

Elmar Brauch
  • 1,286
  • 6
  • 20
  • Thanks for your time and effort, Elmar. I solved it with Apache without having to add additional software. – Mats Andersson Oct 15 '20 at 09:42
  • Apache is also addtional software, because it is not part of Spring Boot. In my answer I listed alternatives for Apache, which replace it. – Elmar Brauch Oct 17 '20 at 07:33
  • Yes, correct. I should have said "additional software to us". We have and use Apache. No value for us in adding something that Apache can already do. – Mats Andersson Oct 18 '20 at 10:14