nGINX上的Django应用部署

问题描述 投票:5回答:4

我想在nGINX服务器上部署Django应用程序。我正在使用uWSGI。我查阅了许多教程,但都没有用。Django应用程序可以作为独立应用程序完美运行。在nGINX上运行相同应用的最简单方法是什么?

我被困在这里,想要一个解决方案..:-(

我的www文件夹在/usr/share/nginx/www

我启用了站点的n conf.d,都在/etc/nginx/

我确实安装了uWSGI,但找不到名为uwsgi的任何文件夹,其中有apps-installed文件夹/文件

python django web-services nginx uwsgi
4个回答
12
投票

一旦创建了dJango应用程序。只需执行以下步骤:

STEP 1。在Django项目目录中创建一个名为uwsgi.ini的文件。即除了manage.py

[uwsgi]
# set the http port
http = :<port_no>

# change to django project directory
chdir = <project directory>

# add /var/www to the pythonpath, in this way we can use the project.app format
pythonpath = /var/www

# set the project settings name
env = DJANGO_SETTINGS_MODULE=<project_name>.settings

# load django
module = django.core.handlers.wsgi:WSGIHandler()

STEP 2在[[/ etc / nginx / sites-available下添加.conf文件

server { listen 84; server_name example.com; access_log /var/log/nginx/sample_project.access.log; error_log /var/log/nginx/sample_project.error.log; # https://docs.djangoproject.com/en/dev/howto/static-files/#serving-static-files-in-production location /static/ { # STATIC_URL alias /home/www/myhostname.com/static/; # STATIC_ROOT expires 30d; } }

STEP 3。在nginx.conf中,将请求传递给Django应用程序

在服务器{}块下,

location /yourapp { include uwsgi_params; uwsgi_pass <your app address, eg.localhost>:<portno>; }

STEP 4。运行uwsgi.ini

> uwsgi --ini uwsgi.ini
现在对您的nGINX的任何请求都将通过uwsgi将请求传递给您的Django应用。        

1
投票
最简单的方法(并且非常有效)是使用Gunicorn,除非您需要坚持使用uWSGI。他们有不错的文档,并且快速且易于部署。

1
投票
尝试远离发行版相关的方法,它们很容易将您推向错误的方向。

0
投票

STEP 1。

© www.soinside.com 2019 - 2024. All rights reserved.