简体   繁体   English

Django-访问并将文件保存到远程服务器

[英]Django - Access and save files to remote server

I am currently developping an application using Django. 我目前正在使用Django开发应用程序。

What I'm trying to achieve is to have a remote server that will host configuration files. 我要实现的目标是拥有一个将承载配置文件的远程服务器。 Those files are going to be numerous but quite small. 这些文件将是很多,但非常小。 The configuration of my server is the following : on the adress 172.xx51 I have my Django app running with uwsgi and on 172.xx52 I have my nginx service connected to my uwsgi instance. 服务器的配置如下:在地址172.xx51上,我的Django应用与uwsgi一起运行,在172.xx52上,我的nginx服务已连接至我的uwsgi实例。

What I would like is to host the files on the nginx server. 我想要的是将文件托管在Nginx服务器上。 Inside the application, I will need to access to the files and to save them (they are calculated from data from the database, so there's no need for a fileupload). 在应用程序内部,我将需要访问文件并保存它们(它们是根据数据库中的数据计算出来的,因此不需要文件上传)。

I looked on the documentation and found that I can use a Custom Storage System. 我查看了文档,发现可以使用自定义存储系统。 The thing is, I don't think that's what I need because I want to store them the way it's done by default. 问题是,我认为这不是我所需要的,因为我想按默认方式将它们存储起来。 I would just like to define the place where the files should be updated from Django. 我只想定义应该从Django更新文件的位置。

Would it be better if I stored them in the media folder on my nginx instance ? 如果将它们存储在我的nginx实例的media文件夹中会更好吗? How would I say to Django to go look on nginx's instance for the files ? 我如何对Django说要查看nginx的文件实例? On the server where nginx is hosted, I already host my static files and it's working. 在托管nginx的服务器上,我已经托管了静态文件,并且可以正常工作。

This isn't a question about Django really. 这真的不是关于Django的问题。 Storage backends are for file uploads, but as you say you're not doing that. 存储后端用于文件上传,但是正如您所说的那样。

You need some way of allowing your Django instance on *.51 write to your nginx server on *.52. 您需要某种方式允许* .51上的Django实例写入* .52上的nginx服务器。 This might be via SSH/SCP, or by sharing directories over NFS, for example. 例如,这可能是通过SSH / SCP或通过NFS共享目录。 Then you can simply save the files over that protocol to the relevant place, from where nginx can serve them. 然后,您可以简单地通过该协议将文件保存到相关位置,nginx可以在该位置提供文件。

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

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