简体   繁体   English

带有Python的Django-Web服务器

[英]Django with Python - webserver

When using django with apache which is the best server config? 将Django与apache一起使用时,最好的服务器配置是什么? Should I use mod_wsgi? 我应该使用mod_wsgi吗?

At this point no configuration has been completed I only have the application code which has been tested using the local development server built into django. 至此,尚未完成任何配置,我只拥有已使用django内置的本地开发服务器测试过的应用程序代码。

Would anyone recommend using another web server application such as nginx? 有人会建议使用其他Web服务器应用程序(例如nginx)吗?

The scheme with Apache is a slower then the following. Apache的方案比以下方案慢。 Use uwsgi (read the next please): http://www.jeremybowers.com/blog/post/5/django-nginx-and-uwsgi-production-serving-millions-page-views/ 使用uwsgi(请阅读下一篇): http : //www.jeremybowers.com/blog/post/5/django-nginx-and-uwsgi-production-serving-millions-page-views/

The Django docs state: Django docs状态:

If you're new to deploying Django and/or Python, we'd recommend you try mod_wsgi first. 如果您不熟悉Django和/或Python,建议您先尝试使用mod_wsgi。 In most cases it'll be the easiest, fastest, and most stable deployment choice. 在大多数情况下,它将是最简单,最快和最稳定的部署选择。

At this point I'd choose Apache + wsgi. 此时,我将选择Apache + wsgi。

Most of the time configuring Django on Apache comes down to this line: 大多数情况下,在Apache上配置Django的原因是:

WSGIScriptAlias / /path/to/project/bin/django.wsgi

And django.wsgi is something like this: django.wsgi是这样的:

#!/usr/bin/python
import djangorecipe.wsgi
application = djangorecipe.wsgi.main('project.settings', logfile='')

I was also going to recommend nginx + fastcgi, as I prefer nginx to lighttpd (it's better mantained, or at least that's been my perception the last few years). 我还打算推荐Nginx + fastcgi,因为我更喜欢Nginx而不是lighttpd(最好是人为维护,或者至少这是我最近几年的看法)。 But it isn't covered by Django docs and the documentation in the nginx site is not as good. 但是Django文档并没有涵盖它,nginx站点中的文档也不是很好。 I'd stick with Apache + wsgi unless you have a good reason not to (you already have nginx or lighttpd running, or have a good reason to think that the difference in performance using fastcgi may be significant for your site). 我会坚持使用Apache + wsgi,除非您有充分的理由不这样做(您已经在运行nginx或lighttpd,或者有充分的理由认为使用fastcgi带来的性能差异可能对您的站点很重要)。 In that case here are two howtos. 在这种情况下, 这里两个方法 The gist of it is that you run a fastcgi server with Django: 其要点是您使用Django运行fastcgi服务器:

python manage.py runfcgi host=127.0.0.1 port=8080 --settings=settings

And then configure nginx to send requests to it: 然后配置nginx向其发送请求:

location / {
     # host and port to fastcgi server
     fastcgi_pass 127.0.0.1:8080;
     # (...)

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

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