简体   繁体   English

Carrierwave + Nginx-提供公共目录中的图像

[英]Carrierwave + Nginx - Serving images from public directory

How to config NGINX to serve uploaded carrierwave files from RAILS_ROOT/public/uploads ? 如何配置NGINX以服务于RAILS_ROOT / public / uploads上传的载波文件? eg: http://deckbuilder.justnetwork.eu//uploads/card/image/173/54.png 例如: 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. 当config.serve_static_assets = true时,将为文件提供服务,但这很慢。 I want NGINX to serve them. 我希望NGINX为他们服务。 The CS, JS and images are getting served. CS,JS和图像都已投放。

Here's a excerpt from my NGINX config: 这是我的NGINX配置的摘录:

  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;
}

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. 我认为我们在服务器上使用类似的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM