documentcloud / jammit

Industrial Strength Asset Packaging for Rails
http://documentcloud.github.com/jammit/
MIT License
1.16k stars 197 forks source link

Jammit + Passenger + Nginx = Asset files are not created #30

Closed ghost closed 14 years ago

ghost commented 14 years ago

I am running Nginx + Passenger on my Production environment (Ubuntu 9.10, Ruby 1.9.1). I am using Jammit to package my CSS/JS in /public/assets. Everything works fine on my OS X dev box. When deploying to Production Jammit does not create any asset files. I've ensured the entire app is owned/writable by the nginx user (which nginx runs under). Manually running the jammit command from the command line correctly creates the asset files.

Also, I checked the HTTP Response for requests for /public/assets/common.css and there were no X Response headers/returned the Nginx 404 page, which makes me think that the request isn't even getting routed to the Rails stack. (I verified I have the Jammit route config existed in routes.rb). Disclaimer: I'm not sure about the validity of this deduction. :)

I then tried to start the application on production using script/server -e production (running it under WEBrick) .. When I curl'd http://localhost:3000/public/assets/common.css the assets folder was created and the common.css was correctly created. So it appears when running under WEBrick Jammit functions properly.

Any counsel around using Jammit with Nginx + Passenger? Will I have to update my Capistrano recipe to manually execute the jammit command?

documentcloud commented 14 years ago

Thanks for reporting this, empire29. I'm using Jammit/Passenger/Nginx as well, but didn't see the problem because I prebuild the asset packages with the jammit command before restarting the server.

As it turns out, this isn't an issue with Jammit, it's an issue with the Nginx expires header configuration that I recommended in the Jammit docs. It can be fixed by adding a passenger_enabled on line to the location block. Here's the relevant discussion:

http://groups.google.com/group/phusion-passenger/browse_thread/thread/2aaccc53d5bb5dab

Here's what the location block should look like:

location ~ ^/assets/ {
  passenger_enabled on;
  expires max;
}

I've updated the documentation at documentcloud.github.com/jammit to match.

I'd still generally recommend changing your deploy recipe to prebuild the assets, simply because you avoid that single slow request for the first user to hit your site, which isn't such a pleasant thing, but it's up to you.

Closing the ticket... Let me know if you have any problems, and we'll re-open it.

ghost commented 14 years ago

documentcloud - Your solution works like a charm. Thanks for the counsel.

I also appreciate the thoughts around prebuild vs build-on-1st-request.