Nginx+uwsgi部署django应用

来源:互联网 发布:ai印花软件 编辑:程序博客网 时间:2024/06/05 21:13

Deploying Django

Django is very probably the most used Python web framework around. Deploying it is pretty easy (we continue our configuration with 4 processes with 2 threads each).

django或许是最好用的python web框架了。部署十分的简单(我们继续我们的4处理器双线程配置)

We suppose the Django project is in /home/foobar/myproject:

假设django项目目录是/home/foobar/myproject:

uwsgi --socket 127.0.0.1:3031 --chdir /home/foobar/myproject/ --wsgi-file myproject/wsgi.py --master --processes 4 --threads 2 --stats 127.0.0.1:9191

(with --chdir we move to a specific directory). In Django this is required to correctly load modules.

Argh! What the hell is this?! Yes, you’re right, you’re right... dealing with such long command lines is unpractical, foolish and error-prone. Never fear! uWSGI supports various configuration styles. In this quickstart we will use .ini files.

[uwsgi]socket = 127.0.0.1:3031chdir = /home/foobar/myproject/wsgi-file = myproject/wsgi.pyprocesses = 4threads = 2stats = 127.0.0.1:9191

A lot better!

Just run it:

uwsgi yourfile.ini

If the file /home/foobar/myproject/myproject/wsgi.py (or whatever you have called your project) does not exist, you are very probably using an old (< 1.4) version of Django. In such a case you need a little bit more configuration:

uwsgi --socket 127.0.0.1:3031 --chdir /home/foobar/myproject/ --pythonpath .. --env DJANGO_SETTINGS_MODULE=myproject.settings --module "django.core.handlers.wsgi:WSGIHandler()" --processes 4 --threads 2 --stats 127.0.0.1:9191

Or, using the .ini file:

[uwsgi]socket = 127.0.0.1:3031chdir = /home/foobar/myproject/pythonpath = ..env = DJANGO_SETTINGS_MODULE=myproject.settingsmodule = django.core.handlers.wsgi:WSGIHandler()processes = 4threads = 2stats = 127.0.0.1:9191

Older (< 1.4) Django releases need to set envmodule and the pythonpath (.. allow us to reach themyproject.settings module).

0 0
原创粉丝点击