Apache ReverseProxy for OWA

Here’s how I was able to get ReverseProxy working on Apache to protect an Exchange 2007 OWA instance. You’ll note that in certain areas I have the same thing multiple times with slight changes in capitalization. Microsoft does not understand case sensitivity nor POSIX compliance. All of the following goes inside a VirtualHost, of course. Please note, this was figured out on my own without official documentation (since I couldn’t find any) and would love to hear if you found something else. We also are not running rpc over https, so I’m not sure if the rpc directories are correct.

<IfModule mod_proxy.c>
SSLProxyEngine on
RequestHeader set Front-End-Https “On”

# Proxy all of the sub-directories, otherwise go to /owa/
# You’ll notice that some of these subdirectories are spelled
# multiple ways – MS can’t give us a definitive answer…

# Fix trailing slash problem
RedirectMatch permanent /$ https://external.mail.server/owa/
RedirectMatch permanent /owa$ https://external.mail.server/owa/

# Needed for Blackberry Phones
<Location /EWS>
ProxyPass https://internal.mail.server/EWS
ProxyPassReverse https://internal.mail.server/EWS
</Location>

# Enables legacy pre 2007 Exchange connections
<Location /exchange>
ProxyPass https://internal.mail.server/exchange
ProxyPassReverse https://internal.mail.server/exchange
</Location>

<Location /Exchange>
ProxyPass https://internal.mail.server/Exchange
ProxyPassReverse https://internal.mail.server/Exchange
</Location>

# Enables legacy pre 2007 Exchange connections
<Location /exchweb>
ProxyPass https://internal.mail.server/exchweb
ProxyPassReverse https://internal.mail.server/exchweb
</Location>

<Location /Exchweb>
ProxyPass https://internal.mail.server/Exchweb
ProxyPassReverse https://internal.mail.server/Exchweb
</Location>

# Enables Windows Mobile ActiveSync
<Location /Microsoft-Server-ActiveSync>
ProxyPass https://internal.mail.server/Microsoft-Server-ActiveSync
ProxyPassReverse https://internal.mail.server/Microsoft-Server-ActiveSync
</Location>

# Something about AutoDiscover is important
<Location /Autodiscover>
ProxyPass https://internal.mail.server/Autodiscover
ProxyPassReverse https://internal.mail.server/Autodiscover
</Location>

<Location /AutoDiscover>
ProxyPass https://internal.mail.server/AutoDiscover
ProxyPassReverse https://internal.mail.server/AutoDiscover
</Location>

<Location /autodiscover>
ProxyPass https://internal.mail.server/autodiscover
ProxyPassReverse https://internal.mail.server/autodiscover
</Location>

<Location /autoDiscover>
ProxyPass https://internal.mail.server/autoDiscover
ProxyPassReverse https://internal.mail.server/autoDiscover
</Location>

# Not sure if we need the rest of these
<Location /OAB>
ProxyPass https://internal.mail.server/OAB
ProxyPassReverse https://internal.mail.server/OAB
</Location>

<Location /public>
ProxyPass https://internal.mail.server/public
ProxyPassReverse https://internal.mail.server/public
</Location>

<Location /Public>
ProxyPass https://internal.mail.server/Public
ProxyPassReverse https://internal.mail.server/Public
</Location>

<Location /rpc>
ProxyPass https://internal.mail.server/rpc
ProxyPassReverse https://internal.mail.server/rpc
</Location>

<Location /RPC>
ProxyPass https://internal.mail.server/RPC
ProxyPassReverse https://internal.mail.server/RPC
</Location>

<Location /Rpc>
ProxyPass https://internal.mail.server/Rpc
ProxyPassReverse https://internal.mail.server/Rpc
</Location>

<Location /rpcwithcert>
ProxyPass https://internal.mail.server/rpcwithcert
ProxyPassReverse https://internal.mail.server/rpcwithcert
</Location>

<Location /RpcWithCert>
ProxyPass https://internal.mail.server/RpcWithCert
ProxyPassReverse https://internal.mail.server/RpcWithCert
</Location>

<Location /UnifiedMessaging>
ProxyPass https://internal.mail.server/UnifiedMessaging
ProxyPassReverse https://internal.mail.server/UnifiedMessaging
</Location>

<Location /unifiedmessaging>
ProxyPass https://internal.mail.server/unifiedmessaging
ProxyPassReverse https://internal.mail.server/unifiedmessaging
</Location>

<Location /unifiedMessaging>
ProxyPass https://internal.mail.server/unifiedMessaging
ProxyPassReverse https://internal.mail.server/unifiedMessaging
</Location>

# Really doubt we need this – should probably remove
<Location /aspnet_client>
ProxyPass https://internal.mail.server/aspnet_client
ProxyPassReverse https://internal.mail.server/aspnet_client
</Location>

# Actual Proxy for OWA (web browser based mail)
ProxyPass /owa/ https://internal.mail.server/owa/
ProxyPassReverse /owa/ https://internal.mail.server/owa/
</IfModule>

Sorry the formatting is a little messed up :(





Please VOTE for this page at: ADD TO DEL.ICIO.US | ADD TO DIGG | ADD TO FURL | ADD TO NEWSVINE | ADD TO NETSCAPE | ADD TO REDDIT | ADD TO STUMBLEUPON | ADD TO TECHNORATI FAVORITES | ADD TO SQUIDOO | ADD TO WINDOWS LIVE | ADD TO YAHOO MYWEB | ADD TO ASK | ADD TO GOOGLE


22 Comments


  1. Thank you very much!
    You save me a lot of “brain time”

    Posted July 13, 2008, 1:05 pm

  2. Great stuff, I’m going to test this out in my lab to verify the RDP connections. I’ll let you know how it works out!

    Jeremy

    Posted July 22, 2008, 8:55 am

  3. […] links >> reverseproxy OR REVERSE-PROXY Apache ReverseProxy for OWA Saved by kristrygg on Fri 03-10-2008 […]

    Posted October 4, 2008, 7:49 pm

  4. Thank you very much for this. I tried to use my old 2003 config and found it somewhat wanting. So far your method is working nicely.

    Posted October 9, 2008, 9:15 am

  5. Indeed, many thanks for sharing.. this works great!

    Haven’t done extensive testing yet but for what its worth I deleted all of the rules at the end under the #Not sure comment (except for the actual /owa proxy of course) and everything appears to be working fine =)

    Posted November 24, 2008, 1:08 am

  6. Looking back at this post with a little more experience under my belt, I’m going to add some comments.

    * The exchange directory appears to be in all lower-case, as does autodiscover
    * I can confirm that the bottom directories really are not needed (unless you are using RPC over HTTPS)
    * The only directories I can see that you really need are:
    (case sensitive)
    /owa
    /EWS
    /Microsoft-Server-ActiveSync
    /autodiscover
    /exchange

    Posted November 24, 2008, 10:08 am

  7. EWS isn’t working for me. Internally, I have no problems accessing ews, but through apache reverse proxy, I get 401 errors.

    Thanks for the rest though.

    Posted December 22, 2008, 9:35 am

  8. Since a 401 error just means that you are unauthorized, I would guess that there is just something not quite right with your testing. Are you using a BIS account and pointing it to your URL and you see in your log the 401 or are you just hitting it with a web browser?

    If you are testing it through BIS, do you have your account information, including AD domain setup correctly? I don’t have a BlackBerry, so I couldn’t tell you the right way to set it up, but I know some people didn’t get it right the first time. How were you able to test it successfully internally?

    Posted December 22, 2008, 10:09 pm

  9. If anybody is still monitoring this thread, can you confirm whether or not this configuration works with Crackberries trying to access Exchange through OWA? I’m currently using Squid as my reverse proxy to OWA and it works just fine with Droids, Windows Mobile phones and regular web browsers. Blackberry claims that it’s an “unsupported” configuration though and refuses to help us get their phones working with it.

    Posted June 22, 2010, 1:13 pm

  10. I’m sorry I can’t really be of any help on this one. We migrated to a Blackberry Enterprise Server (BES) several years ago and shutdown access to BIS through OWA. I can tell you though that Windows Mobile, iPhones, etc. use OWA and Blackberries do not. They use the EWS subfolder, so verify that you have that one setup as well. The Blackberry user would then log in to their BIS account set up their Exchange email address pointing it to the OWA URL (not sure if you are supposed to have the /OWA at the end or not). Then the Blackberry servers hit your servers to send/receive email. HTH, good luck!

    Posted June 22, 2010, 10:26 pm

  11. Kevin- do you remember what version of Apache you used this config with? I’m getting ready to set up a new reverse proxy for my Exchange 2007. I want to make sure the apache build I use is compatible with your tested config. thanks again for posting this, it’s a huge help.

    Posted August 17, 2010, 4:24 pm

  12. @Timothy Oefelein-
    Not sure if you are still struggling with your BlackBerry setup, but this is good to know for anyone reading this. You can get BlackBerry Enterprise Server Express for free now. It’s a much better setup, it gives you a lot more control over the devices than using BIS. There are some limitations in the free version but it’s well worth the time to set it up.

    Posted August 18, 2010, 8:54 am

  13. Mike – I think this was built for Apache 2.0, but should work fine for 2.2 as well.

    Posted August 19, 2010, 9:04 am

  14. Kevin- one other question. Do you remember why /owa is not configured as a <Location /owa>? Does it make any difference if you set it up as a location, or leave it on it’s own as you have here?

    Posted August 26, 2010, 9:44 am

  15. Sorry, Mike, I should have thought about this when you asked your last question, but I did move all of this to Apache 2.2 over a year ago and /owa is in a Location tag now. We do SSL offloading on the load balancers and have moved all the Blackberry devices to a BES server, so here is the full webmail (OWA) config:

    <VirtualHost *:80>
    ServerName webmail.domain.com

    DocumentRoot /data/sites/webmail
    ErrorLog logs/webmail_error_log
    CustomLog logs/webmail_access_log combined

    SSLProxyEngine on
    RequestHeader set Front-End-Https "On"

    RedirectMatch permanent /$ https://webmail.domain.com/owa/
    RedirectMatch permanent /owa$ https://webmail.domain.com/owa/

    # Need to allow activesync pings for push technology
    # Set to 15 minutes
    ProxyTimeout 900

    # Needed for smartphones
    <Location /Microsoft-Server-ActiveSync>
    ProxyPass https://internalserveraddress/Microsoft-Server-ActiveSync
    ProxyPassReverse https://internalserveraddress/Microsoft-Server-ActiveSync
    </Location>

    # Actual Proxy for OWA (web browser based mail)
    <Location /owa>
    ProxyPass https://internalserveraddress/owa
    ProxyPassReverse https://internalserveraddress/owa
    </Location>
    </VirtualHost>

    Posted August 26, 2010, 10:03 am

  16. oops. the blog dropped some of my text, I meant to say why is it not configured as a Location…

    Posted August 26, 2010, 10:21 am

  17. Awesome. thanks a bunch for this post and your help. I have been struggling with our reverse proxy for a while now, but am close to finishing it up now. This helped a lot!

    Posted August 26, 2010, 10:22 am

  18. No problem, good luck!

    Posted August 26, 2010, 10:31 am

  19. This config has been working great for us, for years. Only recently have we had a need for the EWS functionality – and found that didn’t work by default.

    A lot of head-scratching and staring at tcpdump output, I found that if your IIS server is set to use NTLM auth for the EWS site, it will not work through the reverse proxy. The NTML protocol is such that the IIS server will reject the client’s response because its inbound connection (i.e. from your Apache server) doesn’t match up with the client’s information in the NTLM message.

    The easy solution is to use Basic auth instead in IIS. Keep the proxy https end to end and you won’t expose plaintext passwords. Done.

    Posted May 3, 2011, 11:59 am

  20. […] ????Apache ReverseProxy for OWA? ???????OWA(Outlook Web App)???ActiveSync??????? […]

    Posted July 1, 2011, 2:58 pm

  21. Thank you, you saved me lots of work!!!

    Posted September 13, 2011, 1:38 am

  22. That saves the day !!!

    Posted April 23, 2014, 7:57 am

Leave a reply