<VirtualHost *:<%= @params[:server_port] || node['apache']['listen_ports'].first %>>

    ServerName <%= @params[:server_name] %>
    ServerAlias <% @params[:server_aliases].each do |a| %><%= a %> <% end %>
    SSLEngine On


    SSLCertificateFile "<%= @params[:app][:certificate_file] %>"
    SSLCertificateKeyFile "<%= @params[:app][:certificate_key_file] %>"

    WSGIDaemonProcess <%= @params[:wsgi_process_group] %> processes=<%= @params[:processes] %> threads=<%= @params[:threads] %> python-path=<%= @params[:python_path] %>
    WSGIProcessGroup <%= @params[:wsgi_process_group] %>
    WSGIScriptAlias / <%= @params[:wsgi_path] %>

    Alias <%= @params[:app][:static_url] %> <%= @params[:app][:static_root] %>

    <Directory <%= @params[:app][:static_root] %>>
        Order deny,allow
        Allow from all
    </Directory>

    <Directory <%= @params[:app][:install_dir] %>>
        <Files wsgi.py>
            Order allow,deny
            Allow from all
        </Files>
    </Directory>

</VirtualHost>

<VirtualHost *:80>
    ServerName <%= @params[:server_name] %>

    RewriteEngine On
    RewriteRule /(.*) https://<%= @params[:server_name] %>/$1
</VirtualHost>

<VirtualHost *:<%= @params[:server_port] %>>

    ServerName <%= @params[:server_name] %>
    ServerAlias <% @params[:server_aliases].each do |a| %><%= a %> <% end %>
    SSLEngine On


    SSLCertificateFile "<%= @params[:app][:certificate_file] %>"
    SSLCertificateKeyFile "<%= @params[:app][:certificate_key_file] %>"

    WSGIDaemonProcess <%= @params[:wsgi_process_group] %> processes=<%= @params[:processes] %> threads=<%= @params[:threads] %> python-path=<%= @params[:python_path] %>
    WSGIProcessGroup <%= @params[:wsgi_process_group] %>
    WSGIScriptAlias / <%= @params[:wsgi_path] %>

    Alias <%= @params[:app][:static_url] %> <%= @params[:app][:static_root] %>

    <Directory <%= @params[:app][:static_root] %>>
        Order deny,allow
        Allow from all
    </Directory>

    <Directory <%= @params[:app][:install_dir] %>>
        <Files wsgi.py>
            Order allow,deny
            Allow from all
        </Files>
    </Directory>

</VirtualHost>

<VirtualHost *:80>
    ServerName <%= @params[:server_name] %>

    RewriteEngine On
    RewriteRule /(.*) https://<%= @params[:server_name] %>/$1
</VirtualHost>

Remove option to NOT have server_port set for HTTPS
Remove option to NOT have server_port set for HTTPS
