1

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
  • add "apachectl -S" output to your question. Make sure the output matches the virtualhosts you are showing here. – ezra-s Jul 4 '17 at 7:38
0

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

| improve this answer | |
0
server.tomcat.remote_ip_header=x-forwarded-for

server.tomcat.protocol_header=x-forwarded-proto

Reference Link: https://docs.spring.io/spring-boot/docs/1.1.5.RELEASE/reference/html/howto-embedded-servlet-containers.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.