Francis's Octopress Blog

A blogging framework for hackers.

Tracking Rails 3.1 and Asset Pipeline Problems With Apache

Tracking Rails 3.1 and asset pipeline problems with Apache

ubuneu install apache module sudo apt-get install libapache2-mod-xsendfile


LoadModule rewrite_module /usr/lib/apache2/modules/
LoadModule passenger_module /usr/share/ruby-rvm/gems/ruby-1.8.7-p357/gems/passenger-3.0.11/ext/apache2/
#sudo apt-get install libapache2-mod-xsendfile
LoadModule xsendfile_module /usr/lib/apache2/modules/
PassengerRoot /usr/share/ruby-rvm/gems/ruby-1.8.7-p357/gems/passenger-3.0.11
PassengerRuby /usr/share/ruby-rvm/rubies/ruby-1.8.7-p357/bin/ruby

# PassengerMaxPoolSize 10

# DocumentRoot /var/www/enki/public
XSendFile On

RewriteEngine On

# AllowOverride all
# Options -MultiViews
XSendFilePath /var/www/enki

LoadModule headers_module /usr/lib/apache2/modules/
LoadModule expires_module /usr/lib/apache2/modules/

# Some browsers still send conditional-GET requests if there’s a
# Last-Modified header or an ETag header even if they haven’t
# reached the expiry date sent in the Expires header.
Header unset Last-Modified
Header unset ETag
# This required etag module to be enabled. Comment out
FileETag None
# RFC says only cache for 1 year
ExpiresActive On
ExpiresDefault “access plus 1 year”

If you have a module version < 0.10, add this to the virtual host config that needs to send files: XSendFile On XSendFileAllowAbove On This allows any file path (not only those below your VHost root) to be sent through X-Sendfile, which is sort of bad practice. You can either live with it or compile a newer version of the module.

If you got a module version >= 0.10 you can whitelist the allowed paths instead: XSendFile On XSendFilePath /opt/www/awesome-project

Migrating my blog over to Rails 3.1 beta

Enable the asset pipeline

config.assets.enabled = true

config/environments/development.rb (remove or comment out the following line)

#config.action_view.debug_rjs             = true

config/environments/production.rb (add these lines)

# Compress both stylesheets and JavaScripts
config.assets.js_compressor  = :uglifier
config.assets.css_compressor = :scss

mkdir app/assets
git mv public/images app/assets/images
git mv public/javascripts app/assets/javascripts
git mv public/stylesheets app/assets/stylesheets

Finally, in your production environment, don’t forget to statically generate your compiled assets with this Rake task:

RAILS_ENV=production bundle exec rake assets:precompile

It will create files such as these: