Carrierwave + Nginx-提供公共目录中的图像 [英] Carrierwave + Nginx - Serving images from public directory
本文介绍了Carrierwave + Nginx-提供公共目录中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何配置NGINX以提供RAILS_ROOT/public/uploads上传的载波文件? 例如: http://deckbuilder.justnetwork.eu//uploads/card /image/173/54.png
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
当config.serve_static_assets = true时,文件将被提供,但这很慢.我希望NGINX为他们服务. CS,JS和图像都已投放.
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.
这是我的NGINX配置摘录:
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;
}
推荐答案
尝试添加此配置:
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.
这篇关于Carrierwave + Nginx-提供公共目录中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文