I have a Spring Boot application that runs on a Amazon Linux server. I use Apache HTTP server as a proxy server for this application. Recently I installed Let's Encrypt SSL certificate and added a virtual host entry on Apache for that. However, I cannot get it to work with Spring Boot properly. No SSL version seems to be working fine though.
What I observed is that the requests comes to the Spring Boot application when a user calls the https version of it, but user receives a HTTP 404 error from Apache. For example this works fine: http://example.com/oauth/token but this does not work and return 404: https://example.com/oauth/token
I posted the config files below, what am I missing?
vhosts.conf
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
ServerAdmin support@example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog /var/www/example.com/logs/error.log
CustomLog /var/www/example.com/logs/access.log combined
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^(/api/v1) - [L]
RewriteRule ^(/oauth/token) - [L]
RewriteRule ^ /index.html [L]
SSLEngine on
SSLCertificateFile /var/www/example.com/cert/cert.pem
SSLCertificateKeyFile /var/www/example.com/cert/privkey.pem
ProxyPreserveHost on
RequestHeader set X-Forwarded-Proto https
RequestHeader set X-Forwarded-Port 443
ProxyPass /api/v1 http://127.0.0.1:8080/api/v1
ProxyPassReverse /api/v1 http://127.0.0.1:8080/api/v1
ProxyPass /oauth/token http://127.0.0.1:8080/oauth/token
ProxyPassReverse /oauth/token http://127.0.0.1:8080/oauth/token
</VirtualHost>
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
ServerAdmin support@example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog /var/www/example.com/logs/error.log
CustomLog /var/www/example.com/logs/access.log combined
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
RewriteRule ^(/api/v1) - [L]
RewriteRule ^(/oauth/token) - [L]
RewriteRule ^ /index.html [L]
ProxyPreserveHost on
ProxyPass /api/v1 http://127.0.0.1:8080/api/v1
ProxyPassReverse /api/v1 http://127.0.0.1:8080/api/v1
ProxyPass /oauth/token http://127.0.0.1:8080/oauth/token
ProxyPassReverse /oauth/token http://127.0.0.1:8080/oauth/token
</VirtualHost>
application.properties
server.context-path=/api/v1
server.address=127.0.0.1
server.port=8080
server.use-forward-headers=true
server.tomcat.remote_ip_header=x-forwarded-for
server.tomcat.protocol_header=x-forwarded-proto
Best Answer
I believe it should be "server.tomcat.protocol-header" not "protocol_header"
Exampe:
server.tomcat.protocol-header-https-value=https server.tomcat.protocol-header=X-Forwarded-Proto server.tomcat.port-header=X-Forwarded-Port