<IfModule mod_ssl.c>
<Virtualhost *:443>
  ServerName gugg.siora.de

  <IfModule mod_rewrite.c>
    ProxyPreserveHost On
    ProxyRequests Off
    RewriteEngine On

    ## RPi -> FB NAS
    RewriteRule /nas(.*)$  http://10.1.1.254/nas/$1 [P]

    ## RPi -> TRilium
    RewriteRule /notes(.*)$  http://localhost:8081/$1 [P]

    ## RPi Cam Control
    RewriteRule ^(cam)($|/) - [N]
    RewriteCond %{REQUEST_URI} ^/cam
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule /cam/(.*)$  ws://rpi-cam/cam/$1 [P,L]
    RewriteCond %{HTTP:Upgrade} !=websocket [NC]
    RewriteRule /cam/(.*)$  http://rpi-cam/cam/$1 [P,L]

    ## Home-assistant: rewrite to http://<docker-container>
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    # exclude /cam from rewriting:
    #RewriteCond %{REQUEST_URI} !^/cam (not needed since above rewrite rules terminate with [L])
    RewriteRule /(.*)  ws://172.17.0.1:8123/$1 [P,L]
    RewriteCond %{HTTP:Upgrade} !=websocket [NC]
    # exclude /cam from rewriting:
    #RewriteCond %{REQUEST_URI} !^/cam (not needed since above rewrite rules terminate with [L])               
    RewriteRule /(.*)  http://172.17.0.1:8123/$1 [P,L]

  </IfModule>


  SSLCertificateFile /etc/letsencrypt/live/gugg.siora.de/fullchain.pem
  SSLCertificateKeyFile /etc/letsencrypt/live/gugg.siora.de/privkey.pem
  Include /etc/letsencrypt/options-ssl-apache.conf
</Virtualhost>
</IfModule>
