By jcspampinato
Images that exist in my repo and display fine in development are 404 not found in production.
I have confirmed the images are present on the production server in root/assets/images/<subdir>/. The images are not accessible in any subpath I have tried typing into the broswer, unlike locally, where I can get a lone image to display in the browser by adding /<subdir>/<imagename> to the url.
I have added the following lines to my /etc/nginx/nginx.conf: server { root /home/rails/<myproj>;
location /images/ {
root /home/rails/<myproj>/app/assets;
}
}
No change. I manually precompiled assets on the server with no errors.
My /config/environments/production.rb has the line: config.serve_static_files = ENV[‘RAILS_SERVE_STATIC_FILES’].present?
and the rails environment RAILS_SERVE_STATIC_FILES is set to true.
How can I make my images locatable in my production site?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi!
If you are referring to these images from your app, then you need to use image_path in your code, instead of direct link to the image
Docs http://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html
Regards, Sergey
If you’re server block only consists of:
server {
root /home/rails/<myproj>;
location /images/ {
root /home/rails/<myproj>/app/assets;
}
}
The server block really isn’t complete. You can take a look at the error logs for NGINX to see what is or may be causing the issue by running:
tail -20 /var/log/nginx/error.log
If you’ll paste the output of that command to a code block using the </> icon, we can see if there’s a bit of information there that we can use.
Generally though, when it comes to server blocks, you’d have something that looks more like this:
server {
listen 80;
server_name domain.com www.domain.com;
root /home/rails/<myproj>;
location /images {
root /home/rails/<myproj>/app/assets;
}
}
That’s very basic and NGINX would only handle /images for you in this case.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.