与Django一起使用哪个web服务器?(2011年更新使用)

2024-06-06 20:27:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我之所以问这个问题,是因为我是一个初学者,我读过差不多90%的关于Django的文章,但问题是: Django是生成的,在部署时遇到了问题,它是python,而python不是PHP! 当阅读Django教程时,初学者遇到了很大的问题,因为他会发现一个“过时”的教程,例如,如果你学习2008年制作的教程,你会发现他们的语言如下:

to deploy django, use apache, and dont forget to use another server for static files, for example nginx as a reverse proxy!

但现在,我发现一些文章说,制作第二个服务器是无用的,因为在过去,Django是使用mod_python服务的,它使用了大量的资源!所以我的问题是:

  1. 哪一个是最好的VPS,Apache或Nginx,使用最新版本的当然!请不要说:使用轻薄或切诺基。。。
  2. 例如,如果答案是:使用Ngnix,那么,是使用一台服务器还是两台服务器更好,就像过去一样,是使用两台web服务器更好?
  3. 当我检查了我的大脑,我发现只有很少的可用空间,所以我不想学习其他东西,所以你认为100%的Python解决方案可以吗?CherryPy是不是一个完美的解决方案,意思是,CherryPy+Django和basta!没有Apache,没有Nginx,没有比python语言更多的学习!
  4. 据我所读,Django和异步服务器并不是“好朋友”,那么使用Nginx真的有好的选择吗?

更新:增加(4)关于Django和asynchronous。


Tags: todjango服务器语言foruseapache部署
1条回答
网友
1楼 · 发布于 2024-06-06 20:27:33

1 - which one is the best for VPS, Apache or Nginx, using the latest release of course! please dont say: use lighty or cherokee...

两种都可以。

2 - if for example the answer was: use ngnix, then, is it better to use one server or two, as in the past it was better to make two webservers?

关键是Django/Python不应该为您的静态资源提供服务。”两台服务器“可以是不同的物理服务器、实例或虚拟服务器。下面是一个将nginx配置为直接为静态文件提供服务,然后将动态请求传递给Python的示例:

来自https://code.djangoproject.com/wiki/DjangoAndNginx

server {
    listen 80;
    server_name localhost;
    location /site_media  {
        root /media/; # Notice this is the /media folder that we create above
    }
    location ~* ^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|mov) {
        access_log   off;
        expires      30d; 
    }
    location / {
        # host and port to fastcgi server
        fastcgi_pass 127.0.0.1:8080;
        fastcgi_param PATH_INFO $fastcgi_script_name;
        fastcgi_param REQUEST_METHOD $request_method;
        fastcgi_param QUERY_STRING $query_string;
        fastcgi_param CONTENT_TYPE $content_type;
        fastcgi_param CONTENT_LENGTH $content_length;
        fastcgi_pass_header Authorization;
        fastcgi_intercept_errors off;
        }
}

3 - when i've checked my brain, i've found that there is only few free space aviable, so i dont want to learn something else, so do you think a 100% pythonic solution will be ok? CherryPy does it be a perfect solution, mean, CherryPy + Django and basta! no Apache, no Nginx, no more learning than python language!

IMO,设置Apache或nginx非常简单,而且有很多资源。你不需要对他们了解太多就可以设置一些简单的东西。

相关问题 更多 >