0

I have a web server with Nginx and Passenger.

I have uploaded my rails app and got it running. Everything was great, but then I decided to change an image (overwrite it with another one). I did that, and then deployed again. I have verified that the new image was at the assets/images folder.

The problem is that I refreshed the web app, and the html was referencing the old image. It was like this, until I restarted nginx. Isn't any other way to reloading this? Because if i have multiple web app on the same server, I don't want to restarting them all just because I updated one web assets.

My nginx conf:

server {
    # Path to ruby version
    passenger_ruby /home/ubuntu/.rvm/gems/ruby-2.2.1/wrappers/ruby;

    listen       80;
    server_name mydomain.com;
    passenger_enabled on;
    root /var/www/myrailsapp/current/public;
    rails_env production;

    location ~ ^/assets/ {
       expires 1y;
       add_header Cache-Control public;

       add_header ETag "";
       break;
    }

    location ~* .(jpg|jpeg|png|gif|ico|css|js)$ {
      expires 365d;
    }


    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

Do you know what is the problem and how can I avoid to restart nginx for reloading the new image?

ascherman
  • 1,762
  • 2
  • 20
  • 41
  • Take a look at http://stackoverflow.com/a/7116701/2502605 – Roko Oct 05 '15 at 20:09
  • That's the browser caching the image. This is why Rails fingerprints assets via the asset pipeline: http://guides.rubyonrails.org/asset_pipeline.html#what-is-fingerprinting-and-why-should-i-care-questionmark You should consider enabling the assets pipeline and precompiling them when they change. – Sean Huber Oct 05 '15 at 20:43
  • 1
    @Roko - Not a great idea. See: http://www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/ – Sean Huber Oct 05 '15 at 20:45
  • @SeanHuber I have the assets pipeline enabled. In fact, the image is something like "my-image-fa62eadf3c561e06de9372909a1d48530a23ee9afbe514027422ff8e4f71c352.jpg". The problem is that when assets were recompiled, and the another image was created, the html didn't change so It kept referencing the old image. What could it be? – ascherman Oct 05 '15 at 21:07
  • Gotchya. Is this html part of a Rails' view (layout, template, or partial) or are you talking about a static html page (likely under /public). Unless it's static, you are going to need to restart your Rails server (passenger). This is quicker than a full nginx restart. Execute the command `touch /tmp/restart.txt`. Reference: https://www.phusionpassenger.com/library/admin/nginx/restart_app.html#restart-txt – Sean Huber Oct 05 '15 at 21:23
  • Thanks @SeanHuber . What I had to do was restarting passenger! – ascherman Oct 06 '15 at 15:33
  • Glad it worked! Would you mind accepting my answer? – Sean Huber Oct 06 '15 at 15:35

2 Answers2

1

For further references, with the help of @SeanHuber what I had to do was restart just the app on passenger.

I did it running the command:

passenger-config restart-app

For more information: https://www.phusionpassenger.com/library/admin/nginx/restart_app.html#restart-txt

ascherman
  • 1,762
  • 2
  • 20
  • 41
0

Instead of restarting nginx, just restart passenger:

touch <app_dir>/tmp/restart.txt
Sean Huber
  • 3,945
  • 2
  • 26
  • 31