# Apache2 vhost configuration sample for Roundcube
# https://www.linode.com/docs/email/clients/installing-roundcube-on-ubuntu-14-04/

<VirtualHost *:80>
  # Virtual host configuration + information (replicate changes to *:443 below)
  ServerAdmin webmaster@example.com
  ServerName webmail.example.com
  DocumentRoot /var/www/roundcube
  # ErrorLog /var/log/apache2/webmail.example.com/error.log
  # CustomLog /var/log/apache2/webmail.example.com/access.log combined

  # Permanently redirect all HTTP requests to HTTPS
  RewriteEngine on
  RewriteCond %{SERVER_PORT} !^443$
  RewriteRule ^/(.*) https://%{HTTP_HOST}/$1 [NC,R=301,L]
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
  # Virtual host configuration + information (replicate changes to *:80 above)
  ServerAdmin webmaster@example.com
  ServerName webmail.example.com
  DocumentRoot /var/www/roundcube
  # ErrorLog /var/log/apache2/webmail.example.com/error.log
  # CustomLog /var/log/apache2/webmail.example.com/access.log combined

  # SSL certificate + engine configuration
  SSLEngine on
  SSLCertificateFile /etc/apache2/ssl/webmail.example.com/apache.crt
  SSLCertificateKeyFile /etc/apache2/ssl/webmail.example.com/apache.key

  # Roundcube directory permissions + restrictions
  <Directory /var/www/roundcube>
    Options -Indexes
    AllowOverride All
  </Directory>
  <Directory /var/www/roundcube/config>
    Order Deny,Allow
    Deny from All
  </Directory>
  <Directory /var/www/roundcube/temp>
    Order Deny,Allow
    Deny from All
  </Directory>
  <Directory /var/www/roundcube/logs>
    Order Deny,Allow
    Deny from All
  </Directory>
</VirtualHost>
</IfModule>
