我想在nGINX服务器上部署Django应用程序。我正在使用uWSGI。我查阅了许多教程,但都没有用。Django应用程序可以作为独立应用程序完美运行。在nGINX上运行相同应用的最简单方法是什么?
我被困在这里,想要一个解决方案..:-(
我的www文件夹在/usr/share/nginx/www
中
我启用了站点的n conf.d
,都在/etc/nginx/
中
我确实安装了uWSGI,但找不到名为uwsgi的任何文件夹,其中有apps-installed文件夹/文件
一旦创建了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应用。
STEP 1。