在生产服务器中部署Django

问题描述:

首先,请让我明确一下,我是Windows用户,并且对网络世界非常陌生.在过去的几个月中,我一直在学习python和django,这对我来说是很棒的经历.现在,我已经以某种方式创建了一个小项目,希望将其部署到生产服务器中.由于django具有内置的开发服务器,所以对我来说没有问题.但是现在我必须将其部署到生产服务器上,我在Google上搜索了一下,发现Nginx + uWSGI或Nginx + Gunicorn是它的最佳选择.而且由于uWSGI和Gunicord与Windows不兼容,我认为我应该改用Ubuntu或其他Unix系统.

First of all please let me be clear that I am a windows user and very new to the web world. For the past months I have been learning both python and django, and it has been a great experience for me. Now I have somehow created a small project that I would like to deploy in the production server. Since django has its built-in development server there was no problem for me. But now that I have to deploy it to a production server I googled around and found Nginx + uWSGI or Nginx + Gunicorn as the best option for it. And as uWSGI and Gunicord are incompatible with Windows, I think I should adapt Ubuntu or other Unix system.

所以我的问题是:

  1. 请明确说明,因为我将不得不使用上述任一服务器,请向我解释为什么我需要两台服务器?
  2. 如果我必须适应Ubuntu环境,是否需要学习Ubuntu Shell脚本,SSH和其他内容?还是托管服务提供商会帮助我做到这一点?
  3. 请让我知道上述相关事项还需要什么.

非常感谢您的宝贵时间,如果我的问题很la脚,请原谅.希望能得到积极的答复.

Thank you so much for your time and please pardon if my question was a lame question. Hoping for positive response answers.

  1. 典型的配置涉及两个服务器进程(可以在同一台实际硬件或虚拟服务器上一起运行),以便位于前面的代理服务器可以缓冲速度较慢的客户端.例如:慢速客户端将通过请求连接到nginx.Nginx将请求转发给Gunicorn,Gunicorn将做出响应.然后Nginx将立即消耗Gunicorn响应,立即释放Gunicorn资源.到那时,速度较慢的客户端可能会花费很多时间来消耗Nginx的响应,而不会占用过多的服务器资源.双服务器进程模型的替代方法是将异步工作程序与Gunicorn一起使用,并将Gunicorn本身放在前面,或者使用异步同步组合,例如

  1. A typical configuration involves two server processes (which can be run together on the same actual hardware or virtual server) so that the proxy server in front can buffer slow clients. For instance: a slow client will connect to nginx with a request. Nginx will pass the request on to Gunicorn and Gunicorn will respond. Nginx will then consume the Gunicorn response immediately, freeing up the Gunicorn resources right away. At that point, the slow client can take as much time as it wants to consume the response from Nginx without tying up much in the way of server resources. Alternatives to the two-server-process model are to use async workers with Gunicorn and put Gunicorn itself in front, or to use an async-sync combo like Waitress. Nginx in front has the added benefit of doubling as a ready-to-use statics server, though.

请注意,慢速客户端"可以描述:失去连接并挂起TCP套接字直到请求中止超时的手机;速度较慢的手机;各种类型的连接不可靠;故意试图使用服务器资源的敌对拒绝服务客户端;有时,任何旧连接由于任何原因会出现打cup或故障.因此,这是一个几乎影响到所有站点的问题.

Note that "slow clients" can describe: mobile phones that lose their connection and leave the TCP socket hanging until timeout mid-request; mobile phones that are just slow; unreliable connections of all types; hostile denial-of-service clients who are deliberately trying to use server resources; sometimes any old connection that has a hiccup or malfunction for any reason. So this is a problem that will affect nearly any site.

您本身不需要shell脚本,但是习惯Ubuntu会花费一些时间.即使在脚本编写之外,还有很多东西要学习,例如如何使用软件包管理器,如何以不会混淆未来更新的方式安装软件包等如何配置软件包.您肯定必须学习使用SSH.;它是* nix世界中最基本的服务器管理工​​具之一.

You won't need shell scripting per se but getting used to Ubuntu will take some time. There is a lot to learn even outside of scripting, like how to use the package manager, how to configure packages once they're installed in ways that won't confound future updates, etc. And you will definitely have to learn to use SSH; it is one of the most fundamental server administration tools in the *nix world.

学习使用Ubuntu或其他服务器平台的另一种方法是使用平台即服务选项,例如Heroku,因为PaaS托管提供商确实会为您处理所有这些工作.我推荐这种方法.话虽这么说,尽管我认为PaaS对于那些希望专注于开发而不是服务器管理员的人来说是一个不错的选择,无论他们的技能水平如何,但对Linux服务器平台的一点点经验还是很长的路要走的帮助您了解代码在其中运行的环境.因此,即使您选择使用PaaS,您仍然可以从修补Ubuntu中受益匪浅.

An alternative to learning to use Ubuntu or another server platform is to use a Platform-as-a-Service option like Heroku, as PaaS hosting providers really will take care of all of that stuff for you. I recommend this approach. That having been said, even though I think PaaS is a good option for people who want to focus on development and not server admin regardless of their level of skill, it's also true that a little bit of experience with Linux server platforms goes a long way in helping you to understand the environment that your code runs in. So even if you go with PaaS, you would still benefit from tinkering with Ubuntu a little (or a lot).

PaaS的另一个好处是,通常他们的基础架构可以处理交易的Nginx部分(通过代理缓冲缓慢的请求).例如,Heroku就是这种情况.因此,您完全不必担心基础架构的这一部分.

Another benefit from a PaaS is that normally their infrastructure handles the Nginx part of the deal (buffering of slow requests via proxy). This is the case with Heroku, for instance. So you won't have to worry about that part of the infrastructure at all.

问题的这一部分范围太广,无法回答,但是如果您需要澄清,请在评论中让我知道.

This part of the question is too broad to answer, but let me know in the comments if you need clarification.