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.

329 thoughts on “How to switch to/from HTTPS using Apache as a proxy to Tomcat

  1. Choisissez une catégorie de jeux puis cliquez sur le jeu que vous désirez miser. Ici, nous vous prenons l’exemple du jeu Crash qui est un jeu parmi tant d’autres. On choisit le jeu Crash donc. On mise son budget puis on clique sur “Pari”. Dès que vous aurez atteint un code raisonnable, cliquez sur “Récupérer” pour récupérer vos gains. Les critères de mise varient selon l’offre. Généralement, vous devrez miser un certain multiple de votre bonus avant de pouvoir retirer vos gains. Depuis son lancement en 2023, Betify a rapidement su se démarquer dans le marché des casinos en ligne grâce à une interface moderne et une sécurité optimale. Titulaire d’une licence des Antilles néerlandaises, Betify offre une variété impressionnante de jeux, allant des machines à sous aux paris sportifs, en passant par les jeux de table et le casino en direct. Les nouveaux joueurs peuvent profiter d’un spectaculaire bonus de bienvenue allant jusqu’à 500 €, avec des conditions de mise transparentes. Si vous êtes à la recherche d’une expérience de jeu sécurisée et diversifiée, Betify est une option incontournable.
    https://senotodoseme.com/decouvrez-les-avantages-exclusifs-de-betonred-pour-les-joueurs-francais/
    Vortex® est une marque déposée de Chessex Manufacturing. Dice Block™ est une marque commerciale de Chessex. Un abonnement payant au service Nintendo Switch Online (vendu séparément) est nécessaire pour utiliser le nuage des données de sauvegarde. Vita PS4 ‘+scriptOptions._localizedStrings.webview_notification_text+’ ‘+scriptOptions._localizedStrings.webview_notification_text+’ Equipé d’un matériel VR puissant (Casque VR dernière génération HTC FOCUS PRO, veste sensorielle, arme Vortex, fini les ordinateurs dorsaux, place au Streaming), embarquez dans une de nos expériences VR exclusives en équipe de 2 à 6 joueurs (jusqu’à 8 joueurs à Lyon). Les séances du soir commencent à 18h tous les jours avec le secteur jouant à 19h, avec de nombreux bonus et promotions différents que tous les joueurs peuvent réclamer et profiter de leur temps à GGPoker. La liste des options est celle qui doit vous attirer le plus l’attention, ces transferts ont des limites minimales assez élevées. Des effets sonores sympas correspondent bien à ce thème, vous avez la possibilité de commencer à jouer. Une fois que l’argent n’est plus un objet, tous les terrains de golf et les magasins haut de gamme.

  2. While tempting to chase losses, Gates of Olympus 1000 Max Win thrives on streaks. If the reels go cold, regroup, reduce your bet, and strike later. To make your Gates of Olympus experience more convenient and accessible on mobile devices, many online casinos offer a dedicated app that allows you to access the Gates of Olympus slots and many other games directly from your smartphone or tablet. The game also features high volatility, indicating that while wins may not occur as frequently, they can be significant when they do. With a maximum potential payout of 5,000 times your stake, Gates of Olympus offers the chance for big wins. Sign inwith askgamblers account The Free Spins is where this Gates of Olympus game ramped up the excitement with win Multipliers, adding to an overall win multiplier and letting them reach electrifying heights of 100x your bet or more if you’re lucky.
    https://umzugsfreund.at/2025/11/06/lucky-jet-by-1win-a-review-for-indian-players/
    Animate famous historical personalities and watch them come to life in your videos. A fun way to blend history with modern tech! Have you ever imagined that still photos can turn into talking photos? Where the photo can be edited into a video. Besides the iPhone tool, you can try using Wondershare Virbo to make photos talk. You can tap the Image icon to see the original photo or tap the heart to favourite the video. One of the most often asked questions by newcomers during post-processing is “How to animate a still picture?” This can be accomplished using a familiar editor on a laptop or by downloading a dedicated mobile app. In November 2024, the picture editor software Canva received over 1.16 million downloads from users in the United States via the Google Play Store and Apple Store. The Remini app, created by the Italian Bending Spoons, came in second with 763,000 downloads. PicsArt, situated in Florida, ranked third with about 702,000 downloads.

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>