Carrierwave + Nginx - Serving images from public directory

独自空忆成欢 提交于 2019-12-08 10:58:33

问题


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:


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.



来源:https://stackoverflow.com/questions/18915679/carrierwave-nginx-serving-images-from-public-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!