<VirtualHost *:<%= @params[:server_port] %>>
  ServerName <%= @params[:server_name] %>
  <% if @params[:server_aliases] -%>
  ServerAlias <%= @params[:server_aliases].join " " %>
  <% end -%>
  DocumentRoot <%= @params[:docroot] %>

  <Directory <%= @params[:docroot] %>>
    Options <%= [@params[:directory_options] || "FollowSymLinks" ].flatten.join " " %>
    AllowOverride <%= [@params[:allow_override] || "None" ].flatten.join " " %>
    Require all granted
  </Directory>

  <Directory />
    Options FollowSymLinks
    AllowOverride None
  </Directory>

  <Location /server-status>
    SetHandler server-status
    Require local
  </Location>

  RewriteEngine On
  LogLevel info rewrite:trace1
  ErrorLog <%= node['apache']['log_dir'] %>/<%= @params[:name] %>-error.log
  CustomLog <%= node['apache']['log_dir'] %>/<%= @params[:name] %>-access.log combined

  <% if @params[:directory_index] -%>
  DirectoryIndex <%= [@params[:directory_index]].flatten.join " " %>
  <% end -%>

  # Canonical host, <%= @params[:server_name] %>
  RewriteCond %{HTTP_HOST}   !^<%= @params[:server_name] %> [NC]
  RewriteCond %{HTTP_HOST}   !^$
  RewriteRule ^/(.*)$        http://<%= @params[:server_name] %>/$1 [L,R=301]

  RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
  RewriteRule ^.*$ /system/maintenance.html [L,R=503]
</VirtualHost>
