Languages
[Edit]
EN

Spring Boot - forward user protocol information via apache2 proxy

4 points
Created by:
Root-ssh
178170

In this article, we would like to show how to configure Apache2 server with Spring Boot Application to forward information about used protocol in current user request (HTTP or HTTPS information forwarding).

X-Forwarded-Proto header in Spring Boot with Apache 2.
X-Forwarded-Proto header in Spring Boot with Apache 2.

Quick solution:

 

Simple steps:

  1. be sure that, apache2 forwards protocol information with X-Forwarded-Proto header,
  2. create configuration bean in Spring Boot Application.

Note: above configuration was tested under Debina 10, Apache 2.4 and Spring Boot 2.4.

 

Practical example

Edit

If X-Forwarded-Proto is not supported in apache2 server but we can add it manually. We can do it by setting http in HTTP VirtuaServer and https in HTTPS VirtuaServer.

Check the below files to know what is necessary configure it.

Hint: do not forget to restart server or reload configurations after changes.

 

/etc/apache2/sites-enabled/my-domain.com.conf file example:

 

ExampleController.java file example:

 

SpringConfig.java file example:

 

References

Edit
  1. X-Forwarded-Proto - MDN Docs

Alternative titles

  1. Spring Boot - forward http / https protocol via apache2 proxy
  2. Spring Boot - forward schema / protocol via apache2 proxy
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join