[英]Best practice for serving static files
I am developing on a python webserver (Tornado). 我正在python网络服务器(Tornado)上进行开发。 I plan to place this in a production instance with nginx in front. 我计划将其放置在生产实例中,并将其放在nginx的前面。 This will be my first time placing something into a production environment on my own. 这将是我第一次自行将某些东西放入生产环境。 My question is how to setup files/directories for static serving. 我的问题是如何为静态服务设置文件/目录。 For instance my application, allows users to upload photos to the web. 例如我的应用程序,允许用户将照片上传到网络上。 I recieve the requests in Tornado, and save to disk. 我在龙卷风中收到了请求,并保存到磁盘。 However when a user visits their items page, I would rather the images be pulled from a static server. 但是,当用户访问其项目页面时,我宁愿从静态服务器中提取图像。 My question is what is the best practice for getting the images from my dynamic server to the static server? 我的问题是从动态服务器到静态服务器获取图像的最佳实践是什么? Do I rsync the image directory to the static server, then run a cron that delete the images from the dynamic server? 我是否将映像目录同步到静态服务器,然后运行cron从动态服务器删除映像?
Best practice is use shared storage, but if can't use it, than you can use "proxy_store" option from nginx. 最佳实践是使用共享存储,但是如果不能使用共享存储,则可以使用nginx的“ proxy_store”选项。 Example from nginx doc: 来自nginx doc的示例:
location /images/ {
root /data/www;
error_page 404 = @fetch;
}
location @fetch {
internal;
proxy_pass http://backend;
proxy_store on;
proxy_store_access user:rw group:rw all:r;
proxy_temp_path /data/temp;
root /data/www;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.