Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I installed a reverse proxy apache server which handles the SSL encryption for a tomcat. We have a struts web application, and everytime we use response.sendRedirect(), the application falls back into the normal HTTP protocol instead of staying at HTTPS. The application has to run with both protocols, and I can't handle SSL over the tomcat container.

I can use HTTPS and navigate around through links and actions. But if I come to an action that uses redirect, it will be only HTTP. Why is that so?

SSLProxyEngine [off|on] # (Differs between the ssl and the other normal conf)
ProxyPreserveHost On
ProxyPass / http://mysite:1234/
ProxyPassReverse / http://mysite:1234/

This is my config. I thought about switching the http to https in the ssl config but that leads to this:

Bad Gateway

The proxy server received an invalid response from an upstream server. Additionally, a 502 Bad Gateway error was encountered while trying to use an ErrorDocument to handle the request.

How can I get the redirects to stick to HTTPS?

share|improve this question
    
What's an example Location header sent to the client in a redirect? –  Shane Madden Oct 4 '12 at 15:52
    
Well the 302 response header specifies http: as its location... –  Dennis Ich Oct 4 '12 at 16:34
add comment

1 Answer

up vote 0 down vote accepted

If sendRedirect uses a relative path, Tomcat will add absolute elements including scheme (http/https) and servername.

Scheme will default to http unless you override it. The servername will come from the host header which you've carefully passed already.

I had the same problem and used a new Tomcat connector (along side the existing one) on a separate port which overrides the scheme and sets the port for good measure:

<Connector port="8443" protocol="HTTP/1.1" URIEncoding="UTF-8"
                    connectionTimeout="20000"
                    scheme="https" proxyPort="443"/>

Then in Apache, the SSL virtual host has:

ProxyPass / http://<tomcat_server>:8443/

The plain HTTP virtual host continues to use the existing Connector port (8080)

Alternatively, you could hard code the redirect location when calling sendRedirect() but this is obviously inflexible.

share|improve this answer
    
Its working! Thank You very much :) –  Dennis Ich Oct 4 '12 at 16:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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