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.

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

  1. united kingdom casino no deposit bonus 2021, free spins no deposit usa 888 and best online sunplay casino salach
    (Carin) canada no deposit bonus, or
    new online casino australia 2021

  2. best small casinos in vegas – Marylyn – online poker tournaments uk, united
    statesn casino minimum deposit dollar 10 and roulette australia rules, or casoola casino uk login

  3. I loved as much as you’ll receive carried out right here. The sketch is attractive, your authored subject matter stylish. nonetheless, you command get got an edginess over that you wish be delivering the following. unwell unquestionably come more formerly again since exactly the same nearly a lot often inside case you shield this increase.

  4. united statesn roulette builders, free pokies 4u canada and canadian play 24 bet casino no deposit bonus (Nadine) sign up no deposit bonus, or
    top gambling sites usa

  5. Landing a spot in a major US market has never been more accessible. On our platform you can check out find out here across major industries updated every day in a way that actually fits your schedule.

  6. Building a career in city is within reach for anyone who stays organized. On our platform you can browse find a job in the United States for every experience level in city and nationwide in a way that actually fits your schedule.

  7. free spins casino no deposit bonus canada,
    free poker chips no deposit uk and online united statesn casino
    reviews, or chukchansi gold casino

    Take a look at my website bingo codes (Hal)

  8. top online pokies and casinos in united states casino, how to
    win on pokie machines usa and las vegas usa euro casino review; Veronica,
    online no deposit bonus codes, or usa casino age restriction

  9. Starting fresh professionally happens to people every day. Thats the reason our portal makes a difference: you check out at this address updated in real time and apply to as many roles as you want whenever it suits you.

  10. slots bonuses uk, usa casino club mobile and fun snoqualmie casino accommodations (Azucena)
    australia, or new zealandn slots app

  11. gambling taxes australia, download uk bingo game and play slots
    for real money usa, or uk the mill casino coos bay or (Meghan)
    paypal

  12. Having read this I believed it was extremely informative.
    I appreciate you spending some time and energy to put this content together.
    I once again find myself spending a significant amount of time
    both reading and leaving comments. But so what,
    it was still worthwhile!

  13. 10 free spins no deposit casino games machine online (Adriana) uk, best casinos in south
    united states and online real slots australia, or uk casino paypal

  14. Между прочим, если вас интересует Инвестирование с BMM Capital: Управление капиталом и инновации, посмотрите сюда.

    Вот, делюсь ссылкой:

    https://bmmcapital.ru

  15. canada visa slots, us casinos taking canada money and best online
    rtg casino (Dusty) rated united states online casino, or best
    usa online slot sites

  16. real money online poker canada, gambling in ontario australia and is top online pokies and casinos in australia
    same, or free casino chips usa

    Also visit my website – come out bet craps (Kareem)

  17. top online pokies and casinos australian deals, united states silverton casino
    platinum rewards; Caroline, online and lucky lusae slot
    machine, or party casino download united states

  18. Whether youre looking for a fresh start city has a place for you. Right here you can browse browse US job openings by field and salary range and apply in no time — thats why so many professionals have already landed their ideal job using our tools.

  19. Между прочим, если вас интересует Последние новости технологий и обзоры гаджетов, загляните сюда.

    Вот, можете почитать:

    https://skatingforthesoul.ru

  20. casino bingo online free no deposit bonus (Jamika) usa all sites, casinos uk and online casino australia free spins sign up,
    or top usa online poker sites

  21. It’s a pity you don’t have a donate button! I’d definitely donate to this superb blog! I suppose for now i’ll settle for book-marking and adding your RSS feed to my Google account. I look forward to fresh updates and will talk about this website with my Facebook group. Talk soon!

  22. Хорошее резюме помогает но главное — знать где искать. На нашей платформе вы можете оформить заявку бесплатно и сразу же найти прямо здесь прямо в личном кабинете подобранные под вас что делает поиск значительно быстрее и точнее.

  23. 普段からこちらのブログを定期的にチェックしています。
    今回の投稿は興味深く読み応えがあり大変役立ちます。
    セクシーなコスプレ衣装を探している方には
    merrss専門ショップが強くおすすめで、
    種類が多く好みに合わせやすい、
    発送が迅速ですぐに手に入る、
    パートナーへのサプライズプレゼント用に最適です。
    イベントやパーティーで身に着けたりするのにも適しており、
    セクシーだけでなく可愛いデザインも豊富です。
    今後も有益な情報を楽しみにしています。

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>