【问题标题】:Carrierwave + Nginx - Serving images from public directoryCarrierwave + Nginx - 从公共目录提供图像
【发布时间】:2013-09-20 11:29:35
【问题描述】:

如何配置 NGINX 以提供从 RAILS_ROOT/public/uploads 上传的载波文件? 例如:http://deckbuilder.justnetwork.eu//uploads/card/image/173/54.png

当 config.serve_static_assets = true 时,文件得到服务,但这很慢。我希望 NGINX 为他们服务。 CS、JS 和图片正在被提供。

这是我的 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;
}

【问题讨论】:

  • 将上传文件放在单独的目录(公共目录之外)并告诉 ngnix 从那里为它们提供服务怎么样?

标签: ruby-on-rails ruby ruby-on-rails-3 nginx asset-pipeline


【解决方案1】:

尝试添加此配置:

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

  expires 24h; # or whatever you want to use

  add_header Cache-Control public;

  break;
}

我认为我们在服务器上使用了类似的东西。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-12
    • 2020-11-22
    • 2011-07-23
    相关资源
    最近更新 更多