首页 > 其他 > 详细

Django3.0 + nginx + uwsgi 部署

时间:2020-02-04 18:51:01      阅读:70      评论:0      收藏:0      [点我收藏+]

CentOS7.6 下部署Django3.0应用,使用nginx+uwsgi部署:

1. uwsgi部署

在项目的根目录中,新建文件夹 conf, 然后进入conf文件夹,并新建文件 uwsgi.ini, 内容如下:

# mysite_uwsgi.ini file
    [uwsgi]

    # Django-related settings
    # the base directory (full path)
    chdir=/root/EduOnline
    # Django‘s wsgi file
    module=EduOnline.wsgi
    # the virtualenv (full path)

    # process-related settings
    # master
    master=True
    # maximum number of worker processes
    processes=5
    # the socket (use the full path to be safe
    socket=0.0.0.0:8001
    # http=0.0.0.0:8001
    # ... with appropriate permissions - may be needed
    # chmod-socket    = 664
    # clear environment on exit
    vacuum=true
    virtualenv =/root/.virtualenvs/eduonline

    logto=/tmp/mylog.log

  

首先进入文件的根目录要使用命令 uwsgi --http :8000 --module EduOnline.wsgi,然后通过浏览器访问:127.0.0.1:8000 是否能访问首页,如果能访问首页,则说明uwsgi能访问成功,然后通过上面文件的配置,将socket一行注释掉,将http一行释放掉,然后保存并退出,再执行以下命令:

uwsgi -i uwsgi.ini

然后再通过浏览器访问,127.0.0.1:8000,如果能访问到首页,则说明配置文件成功,那么这时如果要用nginx来访问,则需要把socket一行释放掉,http一行注释掉即可,然后保存并执行uwsgi -i uwsgi.ini, 然后查看端口使用处于监听状态:netstat -ntulp |grep 8000, 如果有,则表示这个文件配置成功了

 

2. 配置nginx

进入conf.d文件夹

cd /etc/nginx/conf.d

然后创建文件uc_ningx.conf, 代码如下:

# the upstream component nginx needs to connect to
upstream django {
# server unix:///path/to/your/mysite/mysite.sock; # for a file socket
server 0.0.0.0:8001; # for a web port socket (we‘ll use this first)
}
# configuration of the server

server {
# the port your site will be served on
listen      8000;
# the domain name it will serve for
server_name 127.0.0.1 0.0.0.0 47.104.226.120; # substitute your machine‘s IP address or FQDN
charset     utf-8;

# max upload size
client_max_body_size 75M;   # adjust to taste

# Django media
location /media  {
    alias /root/EduOnline/media;  # 指向django的media目录
}

location /static {
    alias /root/EduOnline/static; # 指向django的static目录
}

# Finally, send all non-media requests to the Django server.
location / {
    uwsgi_pass  django;
    include     uwsgi_params; # the uwsgi_params file you installed
}
}

  保存并退出,然后重启nginx服务:

 service nginx restart

然后输入网址:http://127.0.0.1:8000 如果能访问到首页,则表示nginx配置成功

 

Django3.0 + nginx + uwsgi 部署

原文:https://www.cnblogs.com/VinsonYang/p/12260330.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!