Question:
This is an AWS question, I’m using the Ruby 2.2 (Puma) platform.
My compiled assets (in /public/assets) are served as expected. The other assets in /public are not being served (404).
Where do I configure this? Is this an nginx problem? or a puma problem?
Or is this just an AWS image issue?
Here’s a live example (robots.txt should be served from the root):
http://staging.us-west-2.elasticbeanstalk.com/public/robots.txt
It’s also worth mentioning that the default Passenger platform image works out of the box.
Answer:
So, i’m using the exact same environment and I found the solution with a little google fu:
With rails 4+, in the file:
1 2 |
/config/environments/production.rb |
you should find the following lines near the top of the file
1 2 3 4 |
# Disable serving static files from the `/public` folder by default since # Apache or NGINX already handles this. config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? |
That’s all fine and dandy since we’re using passenger(nginx or apache), but Puma doesn’t handle this for us 🙂
To resolve this…
In your AWS console, go to your elastic beanstalk dashboard for the project in question, and click ‘Configuration’ on the left-hand menu.
Now click the little gear icon in the box titled ‘Software Configuration’
Now you should see a table under ‘Environment Properties’, enter ‘RAILS_SERVE_STATIC_FILES’ into a new field under ‘Property Name’, then type ‘true’ (without the quotes) into the value field, hit apply.
Viola! Now your project is serving static files 🙂