问题
I built an application on my local machine with Python and Django. Its working fine. Now, I would like to automate the process to start my Django application on a production server.
What I have to do to achieve that?
回答1:
Django documentation don't recommend to use Django built-in server on production.
DO NOT USE THIS SERVER IN A PRODUCTION SETTING. It has not gone through security audits or performance tests. (And that’s how it’s gonna stay. We’re in the business of making Web frameworks, not Web servers, so improving this server to be able to handle a production environment is outside the scope of Django.)
It's recommended to use gunicorn or uWSGI to launch your WSGI application :
- How to use Django with gunicorn
- How to use Django with uWSGI
Another good practice, it's to use supervisord to start your process, Then if it dies or get killed for some reason, supervisord will restart this process.
And to finish, use nginx or apache as proxy server, which are strong server that can handle the charge. Most of tutorials or documentations, recommend to use nginx because it's a high-performance HTTP server.
NGINX is a free, open-source, high-performance HTTP server and reverse proxy, as well as an IMAP/POP3 proxy server. NGINX is known for its high performance, stability, rich feature set, simple configuration, and low resource consumption.
Check this to know how to configure them :
- Deploying Gunicorn with nginx
- Deploying uWSGI with nginx
Also before deploy your Django app, read this checklist, to make sure everything is well configured : Django - Deployment checklist
With this architecture and tools, you will be able to launch your gunicorn process with a simple supervisord
command. That's all. Then gunicorn will launch your WSGI application.
来源:https://stackoverflow.com/questions/33930640/how-to-run-my-django-application-automatically-on-production-server