Carrierwave + Nginx - Serving images from public d

2019-06-09 11:23发布

How to config NGINX to serve uploaded carrierwave files from RAILS_ROOT/public/uploads ? e.g: http://deckbuilder.justnetwork.eu//uploads/card/image/173/54.png

The files are getting served when config.serve_static_assets = true but this is slow. I want NGINX to serve them. The CS, JS and images are getting served.

Here's a excerpt from my NGINX config:

  root /var/www/hsdeckbuilder/public;

    try_files $uri/index.html $uri.html $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://localhost:8101;
  proxy_send_timeout 3600;
  proxy_read_timeout 3600;
}

1条回答
看我几分像从前
2楼-- · 2019-06-09 11:42

Try adding this configuration:

location ~ ^/uploads/ {
  root /var/www/hsdeckbuilder/public;

  expires 24h; # or whatever you want to use

  add_header Cache-Control public;

  break;
}

I think we use something like this for our server.

查看更多
登录 后发表回答