I was just setting up a new web app on our staging server and came across something I haven’t run into before…figured I’d post it here in case someone else finds it useful. If you’re having trouble with static files not showing up and you’re running Nginx and Rails 3, read on for all the details on this quick and easy fix.
The Problem:
We’re running Nginx and have several static files that are in a “themes” directory. I kept getting pages that had no images and no styling and figured there must be something going on with the way those files are being called.
The Solution:
It turns out this has to do with a setting in Nginx, but it’s super simple to fix in Rails 3.
Look in /environments/production.rb and you’ll see something like this:
# Specifies the header that your server uses for sending files config.action_dispatch.x_sendfile_header = "X-Sendfile" # For nginx: # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
Change it so it looks like this instead:
# Specifies the header that your server uses for sending files #config.action_dispatch.x_sendfile_header = "X-Sendfile" # For nginx: config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'
You may need to restart Nginx and/or Phusion Passenger.
Afterwards, you should be good to go, with those static files being served just like you expected.