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.
Trusted Deals Online – Intuitive interface, helps users browse items and compare prices quickly
Easy Shopping Spot – Minimalist layout allows quick browsing without confusion
BondNoble Guide – Intuitive interface, content flows logically and is easy to navigate
BondVertex Network – Structured pages provide a reliable and user-friendly environment
Metro Buy Now – Easy-to-use layout, locating products online is convenient and simple
StepWise Online – Guides users naturally through planning their next moves
City Retail Online – Modern look with clear descriptions for each item
SmartPick Store – Easy navigation and helpful content make finding deals simple
Bond Centra Hub – Clean layout, information is easy to find and understand quickly
BetterPathway – Encourages planning and action to achieve meaningful outcomes.
Idea Growth Lab – Inspiring guidance and insights encourage users to scale ideas online
Online Shopping Flex – Convenient design makes browsing items fast and easy
Safe Choice Store – Clean interface, helps users shop comfortably and complete transactions quickly
Effortless Shopping – Products are easy to locate thanks to the simple layout
Learn Online Fast – Informative pages, guides and tips are clear and actionable immediately
RapidClick Shopping – Quick-loading pages make browsing and choosing products easy
Fresh Deals Hub – Well-organized pages make finding great deals simple and enjoyable today
City Saver Shop – Smooth experience, browsing products feels organized and reliable
BondTrustix Hub – Clean design, navigating financial content feels easy and trustworthy
read full details – The information looks real and is easy to follow.
focused success steps – Easy to read and offers practical perspective without fluff.
PathClick Site – Browsing feels intuitive and supports continuous exploration
Forward Growth – Smooth navigation makes exploring self-improvement strategies effortless
BondAllied Path – Straightforward structure supports efficient navigation
New Growth Explorer – Inspiring content, helps users discover opportunities and develop personally online
Value Buying Hub – Well-organized listings help users locate deals quickly and easily
Mindful Growth Site – The message stays positive and easy to absorb
Speed Buy Hub – Pages load quickly, allowing easy and fast purchases
Bond Professionals Hub – Organized content and professional layout make navigating effortless
Professional Strategy Portal – Well-organized pages, learning about collaborations feels effortless
Bond Core Prime – Simple navigation ensures users can access details quickly
International Buying Spot – Organized layout, simplifies worldwide shopping for visitors online
Quick Buy Online – Straightforward interface makes finding items simple and stress-free
Urban Finds – Practical design, helps users locate products without any confusion
NextGen Shopping Portal – Professional layout, exploring products and finding bargains is simple today
Daily Deals Online – Layout is straightforward, helping users shop quickly and comfortably
Smart Cart Click – Clear interface, browsing items feels smooth and simple
Professional Team Hub – User-friendly design, allows teams to connect and work together seamlessly
Smart Savings Hub – Clear categories and easy navigation make shopping enjoyable
Bond Planning Online – Intuitive layout, browsing and understanding investment options is fast and simple
BondStrength Platform – Clear structure makes information simple to follow and explore
ClickSource Lab – Creative design helps users engage and learn new skills
Direction Insights Portal – Smooth navigation helps visitors find meaningful opportunities efficiently
Digital Retail Tools – Structured layout, allows visitors to find solutions and items with ease
SmartBuy Central – Informative content and organized deals make shopping convenient
visit bonded unity net – Navigation was enjoyable since everything loaded quickly and stayed organized.
Urban Marketplace – User-friendly interface, searching for items is fast and convenient
Click Smart Online – User-friendly interface with reliable tips enhances browsing efficiency
NextWayForward – Guides users to new paths and directions for growth and learning.
Product Review Stop – Nicely arranged content that helps you choose faster