V Microsoft Exchange 2013 se prvně objevila funkce Outlok Anywhere (tehdy zvaná „RPC over HTTP“), která umožňovala Outloku 2007 a novějším připojovat se k Exchange serveru i z veřejného internetu pomocí HTTP. Protože samotná Exchange, zvláště v poslední době, trpí různými bezpečnostními chybami a zranitelnostmi (např. zde Daniel Nashed’s Blog (nashcom.de), je žádoucí ji skrýt např. za reverzní proxy s WAF (web application firewallem). Podobné řešení jsem popisoval zde.
Zadáním bylo, aby z veřejného internetu byly přístupné služby:
- Outlook Web Access (OWA) – webové rozhraní pošty
- ActiveSync – přístup mobilních zařízení
- Outlok Anywhere – přístup pro „velký“ Outlook
<VirtualHost *:443>
ServerName mail.vurv.cz
ServerAlias firma.cz
ServerAlias autodiscover.firma.cz
ProxyRequests Off
ProxyPreserveHost Off
RewriteEngine On
SSLEngine On
SSLProxyEngine On
RequestHeader set Front-End-Https On
RequestHeader unset Origin
# Header always set X-Frame-Options SAMEORIGIN
Header set Server Apache
Header unset X-AspNet-Version
Header unset X-OWA-Version
Header unset X-Powered-By
RequestHeader unset Expect early
# SetEnvIf User-Agent ".*MSIE.*" value BrowserMSIE
KeepAlive On
Header unset WWW-Authenticate
Header add WWW-Authenticate "Basic realm=mail.firma.cz"
# Copied from https://github.com/phr0gz/Apache-reverse-proxy-for-Exchange-2010-2013-2016/blob/master/webmail.conf
ProxyVia Full
RequestHeader edit Transfer-Encoding Chunked chunked early
RequestHeader unset Accept-Encoding
Timeout 1800
# copied the end
Redirect / /owa/
# owa
ProxyPass /owa https://mail.firma.cz/owa KeepAlive=on
ProxyPassReverse /owa https://mail.firma.cz/owa
ProxyPass /OWA https://mail.firma.cz/OWA KeepAlive=on
ProxyPassReverse /OWA https://mail.firma.cz/OWA
ProxyPass /Owa https://mail.firma.cz/Owa KeepAlive=on
ProxyPassReverse /Owa https://mail.firma.cz/Owa
# ews -> Exchange Web Services
ProxyPass /ews https://mail.firma.cz/ews KeepAlive=on
ProxyPassReverse /ews https://mail.firma.cz/ews
ProxyPass /EWS https://mail.firma.cz/EWS KeepAlive=on
ProxyPassReverse /EWS https://mail.firma.cz/EWS
ProxyPass /Ews https://mail.firma.cz/Ews KeepAlive=on
ProxyPassReverse /Ews https://mail.firma.cz/Ews
ProxyPass /exchange https://mail.firma.cz/exchange KeepAlive=on
ProxyPassReverse /exchange https://mail.firma.cz/exchange
ProxyPass /Exchange https://mail.firma.cz/Exchange KeepAlive=on
ProxyPassReverse /Exchange https://mail.firma.cz/Exchange
ProxyPass /exchweb https://mail.firma.cz/exchweb KeepAlive=on
ProxyPassReverse /exchweb https://mail.firma.cz/exchweb
ProxyPass /public https://mail.firma.cz/public KeepAlive=on
ProxyPassReverse /public https://mail.firma.cz/public
# oab (Offline Address Book)
ProxyPass /oab https://mail.firma.cz/oab KeepAlive=on
ProxyPassReverse /oab https://mail.firma.cz/oab
ProxyPass /OAB https://mail.firma.cz/OAB KeepAlive=on
ProxyPassReverse /OAB https://mail.firma.cz/OAB
# mapi
ProxyPass /mapi https://mail.firma.cz/mapi KeepAlive=on
ProxyPassReverse /mapi https://mail.firma.cz/mapi
# RPC over http(s) / Outlook Anywhere
# OutlookAnywhere Passthrough On
ProxyPass /rpc https://mail.firma.cz/rpc KeepAlive=on
ProxyPassReverse /rpc https://mail.firma.cz/rpc
ProxyPass /Rpc https://10.0.7.45/Rpc KeepAlive=on
ProxyPassReverse /Rpc https://mail.firma.cz/Rpc
# AutoDiscover -> Autodiscover for non-AD integrated Clients (Mac, eg.)
ProxyPass /autodiscover https://mail.firma.cz/autodiscover
ProxyPassReverse /autodiscover https://mail.firma.cz/autodiscover
ProxyPass /Autodiscover https://mail.firma.cz/Autodiscover
ProxyPassReverse /Autodiscover https://mail.firma.cz/Autodiscover
ProxyPass /AutoDiscover https://mail.firma.cz/AutoDiscover
ProxyPassReverse /AutoDiscover https://mail.firma.cz/AutoDiscover
# Microsoft-Server-ActiveSync
ProxyPass /Microsoft-Server-ActiveSync https://mail.firma.cz/Microsoft-Server-ActiveSync connectiontimeout=900 KeepAlive=on
ProxyPassReverse /Microsoft-Server-ActiveSync https://mail.firma.cz/Microsoft-Server-ActiveSync
Header unset WWW-Authenticate
Header add WWW-Authenticate "Basic realm=mail.firma.cz"
ErrorLog /var/log/httpd/mail.firma.cz_443_error_log
TransferLog /var/log/httpd/mail.firma.cz_443_access_log
SSLCertificateFile /etc/letsencrypt/live/mail.firma.cz/cert.pem
SSLCertificateChainFile /etc/letsencrypt/live/mail.firma.cz/chain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mail.firma.cz/privkey.pem
RequestHeader set X-Forwarded-Proto https
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerExpire off
SSLProxyCheckPeerName off
# Problem with sending file attachments > Bypass 128KByte via ActiceSync (new value 30MByte)
<Directory /Microsoft-Server-ActiveSync>
SSLRenegBufferSize 31457280
</Directory>
BrowserMatch "MSIE [2-6]" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
# MSIE 7 and newer should be able to use keepalive
BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
</VirtualHost>
Výsledná konfigurace vznikla po mnoha pokusech, základem byly tyto články z internetu:
Na straně Exchange 2016 bylo nutno nad adresáři služeb Exchange přidat a povolit „Basic authentication“.
Pro řešení také pomohl tento vynikající článek – Exchange Server 2016 Client Access – přístup klientů.