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.
systematic growth – Very clear guidance, content supports deliberate and focused growth.
ClickForFrameworkClarity – Useful insights that make business frameworks easier to understand.
collabstrategies – Clear and practical, the content helps users understand partnership frameworks quickly.
Framework Navigator – Very clear advice, helps implement growth strategies confidently.
BudgetFriendlyCart – Designed to attract shoppers who prioritize value and savings.
commercialbondhub – Highly reliable, guidance on commercial bonds is clear and easy to implement for businesses.
bizgrowthguide – Step-by-step insights make scaling your business straightforward.
globalenterprisealliances – Informative platform, global alliance strategies are explained clearly and practically.
informed growth hub – Focused on supporting users as they take carefully considered steps.
Business Synergy – Informative and welcoming, making collaboration feel natural.
DealExplorerClick – Efficient platform for quickly finding the best offers.
ClickForSmartGrowth – Informative and easy to follow, makes scaling strategies simple to understand.
ForwardStrategyLab – Highlights methods for proactive planning without overcomplicating the process.
ClickMoment Hub – User-friendly layout, browsing articles and features is simple and enjoyable
insightful learning click – Knowledge shared clearly, learning new ideas feels enjoyable and simple.
market partnership guide – Clear guidance, real examples make strategies understandable.
ClickForRoadmapSuccess – Helpful content that made growth planning easier to follow.
Market Angle Explorer – Very clear insights, helps identify new opportunities quickly.
reliable business network – Messaging communicates confidence, making it attractive for serious corporate partners.
BusinessClarityGuide – Offers straightforward tips that make business ideas easy to grasp.
visionary business planning portal – Great for creating actionable long-term goals and strategies.
smart deals portal – Structured interface and trustworthy offers make browsing simple.
scaleguide – Informative and concise, growth insights are explained in an understandable way.
digitalgrowthblueprint – Practical insights guide online expansion in a clear, structured way.
OnlinePurchasePro – User-friendly and premium, buying items is straightforward.
clarity pathways – Great insights, simplifies tracking progress toward goals.
SmartShoppingClick – Trustworthy content and user-friendly interface enhance the shopping experience.
try this link – Interesting concept, it invites casual investigation.
Future-Ready Ecommerce – Enjoyed how the strategies are explained in a clear, usable way.
ShoppingEcoClick – Smooth navigation and informative content, learning about online shopping is easy.
DigitalShopEase – Shopping experience is intuitive and easily tailored to user preferences.
EnterpriseConnectPro – Helps companies build structured and reliable business relationships.
ClickForShoppingGuidance – Clear and actionable advice for finding the best products online.
discover business plans – Helpful explanations, making strategic thinking approachable.
innovation hub site – Inspires creative thinking and exploration of better solutions.
GlobalOnlineBuyingHub – Found this resource valuable, explanations are concise and easy enough.
secureshopclick – Clear focus on safety, makes shopping feel risk-free and convenient.
ConnectSmart – Great for networking, content looks professional and dependable.
ClickForFreshIdeas – Easy-to-follow advice that encouraged immediate implementation.
ecopartners – Very clear, platform presents sustainable partnership guidance in an understandable way.
Growth Path Portal – Clear design and intuitive navigation make exploring ideas enjoyable
fastbuyhub – Very accessible, shopping online is simple and easy to navigate.
enterprise link network – Clean design and structured content make finding networking opportunities easy.
growth clarity – Insightful content, makes understanding and achieving goals simpler.
найкращі жахи онлайн пригоди для всієї родини HD
next-level strategies hub – Great for exploring forward-looking approaches in business.
MarketNavigatorPro – Well-explained and practical, market insights are easy to apply.
PlanSuccessHub – Helpful advice that clarified my planning process thoroughly.
digital retail platform – Modern interface creates an enjoyable shopping journey.
ActionableStrategyHub – Highlights practical approaches for defining and pursuing clear objectives.