How to configure Nginx with Spree 3? Images not showing in Rail's production mode

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;

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)

Show comments

Submit an answer

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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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;


root /home/spree/[application's name]/current/public;

For more info, check out the section on configuring Nginx in this tutorial: