在nGINX上部署Django app

Kar*_*kde 5 python django web-services nginx uwsgi

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

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

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

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

我确实安装了uWSGI,但找不到任何名为uwsgi的文件夹,其中包含应用程序安装的文件夹/文件

Kar*_*kde 12

一旦你创建了一个dJango应用程序.只需按以下步骤操作:

步骤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()
Run Code Online (Sandbox Code Playgroud)

步骤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;
                  }

       }
Run Code Online (Sandbox Code Playgroud)

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

在服务器{}块下,

location /yourapp {
           include uwsgi_params;
           uwsgi_pass <your app address, eg.localhost>:<portno>;
                   }
Run Code Online (Sandbox Code Playgroud)

步骤4.运行uwsgi.ini

> uwsgi --ini uwsgi.ini
Run Code Online (Sandbox Code Playgroud)

现在对你的nGINX的任何请求都会通过uwsgi将请求传递给你的Django App ..享受:)