简体   繁体   中英

Django: Static/Media Files different server

I have concern with Media files in Django. I am just wondering why some of the tutorials recommends to have a different Server instance for media?

  1. What are the benefit for this?
  2. Does it have a big impact or change of speed of my site?
  3. If I'm going to have a different server for media, what would be the specs(# of RAM, Disk Space, etc.)?

Same question goes for Postgre.


Currently my application is running in GCE.

Python 2.7,Django 1.8 with nginx and uWSGI

Compute Engine instance : n1-standard-2 (2 vCPUs, 7.5 GB memory)

You usually consider separating your app server which runs python, your database and properly the static and media files for different reasons.

One reason is scalability - if you receive high load on your site, you can easily detect the bottleneck and set up another server to share the load.

Your staticfiles and/or media scales besides your app server and database. If your app server can not handle the load anymore, this must not automatically apply to database or static/media content and vice versa. This always depends on your use case. Separating the stuff in front makes you more flexible.

Another reason is security. If there is security hole eg django code, which enables the attacker to run whatever code he/she wants on your host, that other stuff is not directly available on the host.

As mentioned in the django docs you might want to run a very lightweight setup for the staticfiles, without any code execution from within the webserver (no python, php or whatever - just static files)

The hardware requirements rely on your load and the software you'll pick. If you do not expect high load and just have one server available - nothing is wrong with serving the whole stuff from one host. As already told it always depends on what you want to achieve and which requirements you (or your customers) have regarding your setup.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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