简体   繁体   English

在 VPS 上托管多个 Django 实例

[英]Hosting multiple Django instances on a VPS

I'm moving away from WordPress and into bespoke Python apps.我正在从 WordPress 转移到定制的 Python 应用程序。

I've settled on Django as my Python framework, my only problems at the moment are concerning hosting.我已经确定 Django 作为我的 Python 框架,目前我唯一的问题是关于托管。 My current shared hosting environment is great for WordPress (WHM on CloudLinux), but serving Django on Apache/cPanel appears to be hit and miss, although I haven't tried it as yet with my new hosting company.我当前的共享托管环境非常适合 WordPress(CloudLinux 上的 WHM),但在 Apache/cPanel 上服务 Django 似乎是碰运气,尽管我还没有在我的新托管公司尝试过。 - who have Python enabled in cPanel. - 在 cPanel 中启用了 Python。

What is the easiest way for me to set up a VPS to run a hosting environment for say, twenty websites?对我来说,设置 VPS 来为 20 个网站运行托管环境的最简单方法是什么? I develop everything in a virtualenv, but I have no experience in running Django in a production environment as yet.我在 virtualenv 中开发一切,但我还没有在生产环境中运行 Django 的经验。 I would assume that venv isn't secure enough or has scalability issues?我会假设 venv 不够安全或存在可伸缩性问题? I've read some things about people using Docker to set up separate Django instances on a VPS, but I'm not sure whether they wrote their own management system.我读过一些关于人们使用 Docker 在 VPS 上设置单独的 Django 实例的事情,但我不确定他们是否编写了自己的管理系统。

It's my understanding that each instance Python/Django needs uWSGI and Nginx residing within that virtual container?据我了解,每个 Python/Django 实例都需要驻留在该虚拟容器中的 uWSGI 和 Nginx? I'm looking for a simple and robust solution to host 20 Django sites on a VPS - is there an out of the box solution?我正在寻找一个简单而强大的解决方案来在 VPS 上托管 20 个 Django 站点 - 是否有开箱即用的解决方案? I'm also happy to develop one and set up a VPS if I'm pointed in the right direction.如果我指向正确的方向,我也很乐意开发一个并设置一个 VPS。

Any wisdom would be gratefully accepted.任何智慧都会被感激地接受。

Andy:)安迪:)

Traditional approach传统方法

  • Virtualenv is good enough and perfectly ready for production use. Virtualenv 已经足够好,完全可以用于生产环境。 You can have multiple virtualenv for multiple projects on the same VM.您可以为同一 VM 上的多个项目拥有多个 virtualenv。
  • If you have multiple database engines for multiple projects.如果您有多个项目的多个数据库引擎。 Like, MySQL for one, PostgreSQL for another something like this then you just need to set up each individually.比如,一个是 MySQL,另一个是 PostgreSQL,然后你只需要单独设置每个。
  • Install Nginx and configure each according to project.安装 Nginx 并根据项目进行配置。
  • Install supervisor to manage(restart/start/stop) each project individually.安装主管以单独管理(重新启动/启动/停止)每个项目。
  • Anything that required by the project.项目需要的任何东西。
    Here it has a huge drawback.在这里它有一个巨大的缺点。 Because you can't use different versions on your database engine for a different project in an easy way.因为您不能以简单的方式在数据库引擎上为不同的项目使用不同的版本。 So, containerization is highly recommended.因此,强烈建议使用容器化。

For simple and robust solution,对于简单而强大的解决方案,

  • Use Docker(docker-compose) for local and production deployment.使用 Docker(docker-compose) 进行本地和生产部署。
  • Configure uWsgi with Nginx(Available on docker.)使用 Nginx 配置 uWsgi(在 docker 上可用。)
  • Create a CI/CD pipeline with any tool like Jenkins.使用 Jenkins 等任何工具创建 CI/CD 管道。
  • Monitor your projects using any good tool like Raygun.使用 Raygun 等任何好的工具来监控您的项目。

That's it.而已。

I created a bash script that deploys as many websites as you want on your server.我创建了一个 bash 脚本,可以在服务器上部署任意数量的网站。 It automatically installs all dependencies on your server, creates a virtual environment, configure Gunicorn, Nginx, and a database for Django, etc. Check it out:它会自动在您的服务器上安装所有依赖项,创建虚拟环境,配置 Gunicorn,Nginx 和 Django 的数据库等。检查一下:

https://github.com/jdbit/django-auto-deploy https://github.com/jdbit/django-auto-deploy

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

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