0

I'm working on a very small scale website for my school (less than 100 users a day) and was wondering if there was a way too store static files on the django server instead of deploying a second server to manage static files. Google searches turn up things like the following: https://docs.djangoproject.com/en/dev/howto/static-files/, but I'm wondering if there was a more simple way to do this, even if it wasn't very efficient, on the Django server.

4

2 回答 2

3

Yes it's certainly possible to serve the static files using the same server. The doc give an example of doing this using Apache/mod_wsgi https://docs.djangoproject.com/en/1.4/howto/deployment/wsgi/modwsgi/#serving-files

If, however, you have no option but to serve media files on the same Apache VirtualHost as Django, you can set up Apache to serve some URLs as static media, and others using the mod_wsgi interface to Django.

It's worth noting that when the docs reference using a separate web server it does not necessarily mean another box (virtual or physical) just a separate server optimized for serving static resources. From https://docs.djangoproject.com/en/1.4/howto/static-files/#serving-static-files-from-a-dedicated-server

Most larger Django apps use a separate Web server -- i.e., one that's not also running Django -- for serving static files. This server often runs a different type of web server -- faster but less full-featured.

A common setup would be to run Nginx for static resources in front of Apache/mod_wsgi, Gunicorn or uWSGI as the WSGI server which for a small site could be done on a single server.

于 2012-07-29T20:17:38.390 回答
2

If by "Django server", you mean the development server that is run by python manage.py runserver, that I would advise against this.

It is really a bad idea to run the Django development server in any sort of production environment as well as serve static files through it. I don't think that the staticfiles app will even let you if DEBUG = FALSE.

However, if you mean to serve static content through the same web server (lighttpd, apache, nginx) that is serving the Django application, then you can do that easily by running python manage.py collectstatic in the project directory to copy all static files into one directory and configuring the web server to serve from that directory as you would any other static site.

于 2012-07-29T20:26:25.147 回答