I’m writing this down because it too me an age to figure out a way of doing this. I have a website which Tomcat is happily serving. Areas of the site require a secure connection so I’m using Spring security to require particular URLs to be accessed over HTTPS. It means that when I access http://example.org:8080/webapp/login, it’ll bump me to https://example.org:8443/webapp/login. Note: Tomcat is setup with the SSL connector and a self signed .keystore see (http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html).
I have two vhosts setup in Apache, one for the http://example.org and one for https://example.org. They are both using mod_proxy to ProxyPass and ProxyPassReverse requests to the appropriate Tomcat URL’s. The problem comes when switching to HTTPS from HTTP and vice versa. Ideally I wanted some sort of ProxyPassReverse declaration in my config for http://example.org what would change HTTP headers (that Spring sets) for https://example.org:8443/webapp into https://example.org. Except ProxyPassReverse doesn’t work like that.
Now, I realise I could simply not use Spring to manage which parts of the site should be accessed over HTTPS and which should not…and just setup Apache to redirect as appropriate. I don’t want to do that though, because that makes the task of adding these restrictions a deploy time task, rather than a development time task. I don’t want to risk someone forgetting to add new restrictions when deploying the webapp and I’d much rather the developer added these restrictions when they were working on the task and really thinking about where and when they are needed.
So, how do I solve the problem so that the app can manage its secure-ness and I can setup Apache once and forget about it? The answer is to ProxyPassReverse onto a “special” URL, which when accessed will redirect to the HTTPS (or HTTP) site. For example, if the HTTP site needed to redirect to the HTTPS site, I’d add rules like so to perform the redirect:
# Proxy a request (from the server) to switch to https onto a special URL "/2https/"
ProxyPassReverse /2https/ https://example.org:8443/webapp/
# When a client requests a URL prefixed with "/2https" map it onto the secure site
RewriteRule ^/2https/(.*)$ https://example.org/$1 [R,L]
…and you’d add something similar to the secure site Apache config. As long as I don’t mount any pages at /2http or /2https I should be ok. Note a couple of things:
- You’ll need “SSLProxyEngine on” and “RewriteEngine on” and obviously the appropriate Apache modules loaded for these commands.
- Because of the redirect between HTTP <-> HTTPS you won’t be able to POST data between them directly (I’m not sure why you’d NEED to though)
- Obviously you’ll need to setup Apache with an SSL certificate…but that is a different story
I should say a special thanks to this random site – from whence the idea actually came from. If anyone has any better ideas on how to do it I’d love to hear them. Please comment below.
Services – Services are easy to locate, and the layout is intuitive.
Durable Link site – Intuitive pages with concise, readable content throughout.
Documentation – Clean pages, fast navigation, and content is reliable.
Collective Anchor website – Consistently smooth and simple to use.
Covenant Bond – Informative and easy to read, content is clear without feeling heavy.
Blog – Modern pages, quick loading, and information is digestible.
LA Portal – Professional appearance, responsive design, and content is straightforward.
Victory Bond Connect – Pages load fast, design is clean, and content is concise and user-friendly.
Trusted Legacy Explorer – Site structure is clear, making it easy for users to browse effectively.
Trust Hub Online – Navigation flows smoothly, interface feels polished, and content is readable.
Bond Connect – Navigation is intuitive, and information is easy to understand.
Press – News articles are easy to navigate, and sections are well spaced.
Paragon Connect – Navigation is smooth, structure feels organized, and content is simple to digest.
Events – Organized pages, simple to browse, and information is easy to locate.
Summit Hub – Pages load fast and navigation feels intuitive throughout the site.
Bond Online – Well-organized design, fast pages, and content is easy to scan.
Team – Staff profiles are easy to read, and the page layout is organized.
Bonding guide – Straightforward details presented in a clean way.
Portfolio – Neat structure, intuitive menus, and content looks professional.
CrestLink portal hub – Clean design, easy-to-read information, and smooth browsing experience.
Shop – Smooth experience, pages are nicely structured and easy to navigate.
DesignDock – Very clear structure, and guidance is practical.
Merit Hub – Clean layout, fast-loading pages, and information is easy to understand.
Vigilant Bond Connect – Pages load fast, structure is neat, and information is easy to understand.
Blog – Posts are engaging, and browsing between articles is simple.
Resources – Minimalist layout, simple menus, and content feels professional.
Unified Anchor Resource Center – Pages load quickly and are structured for easy understanding.
Paramount Network – Intuitive navigation, clean design, and content is easy to read.
IB Central – Organized sections, smooth scrolling, and information is easy to scan.
Surefoot Link – Fast-loading pages and straightforward navigation improve usability overall.
FAQ – Organized pages, clear menus, and explanations are easy to grasp.
The Bridge Spot – Straightforward design and everything renders fast, enjoyable browsing experience.
Home – Navigation is smooth, pages load quickly, and content is easy to follow.
CrestPoint network – Practical content with an organized interface that’s simple to use.
TrendCircle – Interactive articles and smooth layout make staying current enjoyable.
Bonding website – Quick loading pages with useful and concise information.
Tutorials – Smooth browsing experience and content is clear.
Home – The homepage loads quickly, and navigation feels effortless.
The Merit Hub – Pages load quickly, layout is tidy, and content is simple to scan.
site access – The layout feels calm, navigation is intuitive, and content is well organized
Vital Bonding Guide – Layout is organized, browsing is smooth, and content is easy to understand.
Visit Site – Layout is crisp, browsing is easy, and content feels trustworthy and clear.
PF Central Online – Smooth browsing, well-laid-out pages, and information is straightforward.
IB Hub Online – Pages load fast, interface is intuitive, and information is clear.
SurePath Resource – Users can easily access content thanks to clear menus and well-structured information.
Unity Harbor Insight – Fast page load and readable design make the experience efficient.
ZenPath Insights – Smooth browsing experience with simple navigation and readable content.
go to site – Simple idea, clear execution, and encourages users to share and learn together
Testimonials – Clean pages, intuitive navigation, and reading is effortless.
Merge Space – Pleasant first impression, intuitive design, and smooth navigation throughout.