How to switch to/from HTTPS using Apache as a proxy to Tomcat

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.

4,064 thoughts on “How to switch to/from HTTPS using Apache as a proxy to Tomcat

  1. Superbet, Betano e Novibet são plataformas com bônus de cadastro no Brasil. As recompensas variam entre apostas grátis, giros em slots selecionados e prêmios por ações realizadas logo após o registro. A Multibet se destaca por deixar livres para ativação de 10 a 20 giros grátis nos jogos slots mais populares desde o nosso cadastro. Só precisamos de pontos, que acumulamos completando missões. COPYRIGHT © 2015 – 2025. Todos os direitos reservados à Pragmatic Play, um investimento da Veridian (Gibraltar) Limited. Todo e qualquer conteúdo incluído neste site ou incorporado por referência está protegido por leis internacionais de direitos autorais. Superbet, Betano e Novibet são plataformas com bônus de cadastro no Brasil. As recompensas variam entre apostas grátis, giros em slots selecionados e prêmios por ações realizadas logo após o registro.
    https://reactos.org/forum/memberlist.php?mode=viewprofile&u=179911
    Yggdrasil Gaming é um desenvolvedor de jogos de cassino on-line e móveis com sede em Malta, desde 2013. A empresa é especializada em slots de vídeo on-line e móveis, jogos de loteria de vídeo e jogos de raspadinha. Além disso, a empresa é membro da Associação Sueca de Jogos (SPER), comprometendo-se com as diretrizes éticas do órgão. Os jogos da Yggdrasil são encontrados em vários cassinos Yggdrasil Gaming, que são verificados pela eCOGRA como confiáveis e imparciais. Joker 3600 captivates players with its straightforward yet thrilling gameplay. This slot game boasts six reels and expanding paylines that increase the excitement. The game’s theme revolves around classic fruit symbols while integrating modern slot mechanics. Players will find familiar symbols like cherries, lemons, stars, and, of course, jokers.

  2. If you’re curious about Greek gods or want to see a slot showered in lightning, the Gates of Olympus simulator feels like an over-caffeinated episode of “Ancient Aliens.” Right here, you can test-drive the free Gates of Olympus slot simulator without downloads or forms. The best part: your coins are fully fictional, so you get every feature, wild tumble, and “Zeus zap” without using real money bets. This is a good way to understand wild multipliers and epic bonus rounds, although keep in mind that no simulator spin brings you closer to a real payout. The VideoSlots online casino team has worked hard to earn its reputation as a creative, it may take some time to find the perfect title. Thanks to the Scatter symbol, Neteller. The idea is that during certain hours or times of the day, the slot may be more “generous” with wins. This is likely due to the betting activity of players in the casino or algorithmic peculiarities, though there is no official confirmation of this. However, practical observation has shown that sometimes you can notice patterns when wins happen more frequently.
    https://inovexiasoftware.com/bonza-spins-ultimate-casino-review-for-australian-players/
    In this part of our Gates of Olympus Super Scatter review, we’ll look into the slot’s pros and cons to help UAE players decide if it’s worth their time. This is what we found out: News of this release excited us greatly as fans of the series, and Gates of Olympus Super Scatter by Pragmatic Play is everything we could have hoped for and more. Lower-paying symbols are blue, green, yellow, purple and red precious stones, while the higher-paying symbols are a cup, a ring, an hourglass, and a crown. Scatter wins of 8-9 OAK are worth 0.25x to 10x, or get lucky and hit 12+ of a kind to win 2 to 50 times the bet. Substitutions do not occur in this game since Gates of Olympus Super Scatter does not have wild symbols on any of its reels. As before, the game utilises a tumble mechanic, which means that when a win hits, the winning symbols disappear, and new ones fall in from above. This continues as long as new wins keep landing.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>