Skip to content

Customizing default virtual host

technicalpickles edited this page Dec 11, 2012 · 4 revisions

Moonshine tries to provide a good default for your Apache virtual host. You can see everything it does in the template. This should be enough for most cases, but you may need to customize it further. Rewrite rules, redirects, whatever. Fortunately, moonshine has an option for that: configuration[:passenger][:vhost_extra]. Anything you configure for that will be included in the virtual host.

There's two ways to add this to your configuration:

  • Using YAML in config/moonshine.yml (or config/moonshine/STAGE.yml)
  • Using Ruby in app/manifests/application_manifest.

Here's an example using YAML. It uses the | to have a multi-line string with newlines preserved.

:passenger:
  # other passenger settings go here
  :vhost_extra: |
    AddType application/x-mpegURL .m3u8
    AddType video/MP2T .ts

For more complex examples, you may want to put this into a template, so you can dynamically generate the extra configuration. Here's an example where we store the extra configuration in a template, then configure moonshine to use it. In app/manifest/application_manifest.rb:

class ApplicationManifest < BaseManifest

 configure :passenger => { :vhost_extra => template('app/manifests/templates/vhost_extras.erb') }

 recipe :default_stack
 # rest of your manifest
end

Anything in app/manifests/templates/vhost_extras.erb will now be rendered as a template into /etc/apache2/sites-enabled/APP.

Clone this wiki locally