在nGINX上部署Django应用程序 [英] Django app deployment on nGINX
问题描述
我想在nGINX服务器上部署Django应用程序。我正在使用uWSGI。我抬头看了许多教程,但没有工作。
Django应用程序作为独立应用程序运行完美。在nGINX上运行相同的应用程序是最简单的方法?
I want to deploy Django application on nGINX server. I'm using uWSGI. I looked up in many tutorials but none worked. Django application runs perfectly as a standalone app. What is the simplest way to have the same app running on nGINX??
我被困在这里,想要一个解决方案..: - (
I'm stuck here and want a solution.. :-(
我的www文件夹位于 / usr / share / nginx / www
my www folder is in /usr/share/nginx/www
我的网站启用了n conf.d
,都在 / etc / nginx /
my site-enabled n conf.d
and all are in /etc/nginx/
我没有安装uWSGI,但找不到任何名为uwsgi的文件夹,其中有 apps-installed 文件夹/文件
I did install uWSGI but couldn't find any folder named uwsgi which has apps-installed folder/file in it
推荐答案
创建dJango应用程序后,请按照以下步骤操作:
Once you have created an dJango application. Just follow these steps:
步骤1。 >在Django项目目录中创建一个文件uwsgi.ini,即除了manage.py
STEP 1. Create a file say uwsgi.ini in your Django Project Directory. i.e besides 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()
步骤2。在 / etc / nginx / sites-available 添加.conf文件
STEP 2. Under /etc/nginx/sites-available add .conf file
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;
}
}
步骤3. 在nginx.conf中,将请求传递给您的Django应用程序
STEP 3. In nginx.conf, pass the request to your Django application
在服务器{}块下,
location /yourapp {
include uwsgi_params;
uwsgi_pass <your app address, eg.localhost>:<portno>;
}
步骤4。运行uwsgi.ini
STEP 4. Run the uwsgi.ini
> uwsgi --ini uwsgi.ini
现在,您对nGINX的任何请求都会将请求传递给您的Django应用程序通过uwsgi ..享受:)
Now any request to your nGINX will pass the request to your Django App via uwsgi.. Enjoy :)
这篇关于在nGINX上部署Django应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!