Django3.0 + nginx + uwsgi 部署

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

1. uwsgi部署

pip install uwsgi

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

1# mysite_uwsgi.ini file 2 [uwsgi] 3 4 # Django-related settings 5 # the base directory (full path) 6 chdir=/root/EduOnline 7 # Django's wsgi file 8 module=EduOnline.wsgi 9 # the virtualenv (full path) 10 11 # process-related settings 12 # master 13 master=True 14 # maximum number of worker processes 15 processes=5 16 # the socket (use the full path to be safe 17 socket=0.0.0.0:8001 18 # http=0.0.0.0:8001 19 # ... with appropriate permissions - may be needed 20 # chmod-socket = 664 21 # clear environment on exit 22 vacuum=true 23 virtualenv =/root/.virtualenvs/eduonline 24 25 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

安装nginx步骤

a.  Add Nginx Repository

sudo yum install epel-release

b.  Install Nginx

sudo yum install nginx

c. Start Nginx

sudo systemctl start nginx

d. 设置防火墙

1sudo firewall-cmd --permanent --zone=public --add-service=http 2sudo firewall-cmd --permanent --zone=public --add-service=https 3sudo firewall-cmd --reload最后访问你的ip地址: 4 5http://server_domain_name_or_IP/

进入conf.d文件夹

cd /etc/nginx/conf.d

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

1# the upstream component nginx needs to connect to 2upstream django { 3# server unix:///path/to/your/mysite/mysite.sock; # for a file socket 4server 0.0.0.0:8001; # for a web port socket (we'll use this first) 5} 6# configuration of the server 7 8server { 9# the port your site will be served on 10listen 8000; 11# the domain name it will serve for 12server_name 127.0.0.1 0.0.0.0 47.104.226.120; # substitute your machine's IP address or FQDN 13charset utf-8; 14 15# max upload size 16client_max_body_size 75M; # adjust to taste 17 18# Django media 19location /media { 20 alias /root/EduOnline/media; # 指向django的media目录 21} 22 23location /static { 24 alias /root/EduOnline/static; # 指向django的static目录 25} 26 27# Finally, send all non-media requests to the Django server. 28location / { 29 uwsgi_pass django; 30 include uwsgi_params; # the uwsgi_params file you installed 31} 32}

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

 service nginx restart

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

如果访问出现 css和js样式不对,以及报403 Fobbien 的错误,则表示nginx user权限不够,需要设置nginx.conf的头部user: root

点赞
收藏

评论区

加载中...

相关推荐

MySQL:[Err] 1292 - Incorrect datetime value: ‘0000-00-00 00:00:00‘ for column ‘CREATE_TIME‘ at row 1

文章目录问题用navicat导入数据时,报错:原因这是因为当前的MySQL不支持datetime为0的情况。解决修改sql\mode:sql\mode:SQLMode定义了MySQL应支持的SQL语法、数据校验等,这样可以更容易地在不同的环境中使用MySQL。全局s

Oracle 分组与拼接字符串同时使用

SELECTT.,ROWNUMIDFROM(SELECTT.EMPLID,T.NAME,T.BU,T.REALDEPART,T.FORMATDATE,SUM(T.S0)S0,MAX(UPDATETIME)CREATETIME,LISTAGG(TOCHAR(

MySQL部分从库上面因为大量的临时表tmp_table造成慢查询

背景描述Time:20190124T00:08:14.70572408:00User@Host:@Id:Schema:sentrymetaLast_errno:0Killed:0Query_time:0.315758Lock_

皕杰报表之UUID

​在我们用皕杰报表工具设计填报报表时,如何在新增行里自动增加id呢?能新增整数排序id吗?目前可以在新增行里自动增加id,但只能用uuid函数增加UUID编码,不能新增整数排序id。uuid函数说明:获取一个UUID,可以在填报表中用来创建数据ID语法:uuid()或uuid(sep)参数说明:sep布尔值,生成的uuid中是否包含分隔符'',缺省为

手写Java HashMap源码

HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程HashMap的使用教程22

2020年前端实用代码段,为你的工作保驾护航

有空的时候,自己总结了几个代码段,在开发中也经常使用,谢谢。1、使用解构获取json数据let jsonData  id: 1,status: "OK",data: 'a', 'b';let  id, status, data: number   jsonData;console.log(id, status, number )