I am trying to integrate Spree a popular ecommerce extension for Rails into my app. Every works fine except the images don’t show when run in production mode. So I searched and found that people are running into the same problem and the way to solved it is by reconfiguring the Nginx config file in /etc/nginx/sites-enabled
Now, my default config file is like so …
upstream app_server { server [YOUR IP ADRESS] fail_timeout=0; }
server {
listen 80;
root /home/rails/public;
server_name _;
index index.htm index.html;
location / {
try_files $uri/index.html $uri.html $uri @app;
}
location ~* ^.+\.(jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|mp3|flv|mpeg|avi)$ {
try_files $uri @app;
}
location @app {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_pass http://app_server;
}
}
However, it was solution was solved by add this line in the nginx cofig file above
location ~ ^/(system|assets|spree)/ {
root /home/spree/[application's name]/current/public;
expires max;
break;
}
Here are the references of the solution I found… 1st link from google group 2nd link from google group 3rd link from spree documentation
My quick solution, which works right now, is to set my Rails application in production mode to serve static files (go to production.rb and make serve_static_files to true)… but it was said that this would increases the work load of rails unnecessarily instead of having nginx do it.
So I am trying to find the proper solution to this. I tried add the suggested lines below my nginx config in sites-enabled … still nothing shows up … how do I go about this? I am stuck. Please help!
Btw, I am running on Ubuntu Ruby on Rails on 14.04 (Postgres, Nginx, Unicorn)
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!
To serve static assets directly with Nginx, you must make sure that the root is pointed to the location of your application’s public/ folder. So in your configuration above, you would need to change:
root /home/rails/public;
to:
root /home/spree/[application's name]/current/public;
For more info, check out the section on configuring Nginx in this tutorial:
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.