26 juin 2009

Rails assets and Apache SSL

In a current project, I use calls to assets.mycoolsite.com to improve load times. However, we only have one server with one IP address, so ultimately all calls point to the same IP address.

This becomes important when you start using SSL. Unfortunately, Apache cannot recognize 2 different NameVirtualHost at the same IP address in SSL mode... Bummer!

Rails to the rescue!

  1. Install Asset hosting with minimum SSL from his majesty DHH himself:
    script/plugin install git://github.com/dhh/asset-hosting-with-minimum-ssl.git

    (Warning though: it requires a version of Rails > 2.2, so you have to be ready to upgrade: see README for more details)
  2. In production.rb:
    config.action_controller.asset_host = AssetHostingWithMinimumSsl.new(
    "http://assets%d.example.com", # will serve non-SSL assetts on http://assets[1-4].example.com
    "https://assets1.example.com"  # will serve SSL assets on https://assets1.example.com
    )


Aucun commentaire:

Enregistrer un commentaire