Django3.0 + nginx + uwsgi 部署
CentOS7.6 下部署Django3.0应用,使用nginx+uwsgi部署:
1. uwsgi部署
pip install 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
安装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. 设置防火墙
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
最后访问你的ip地址:
http://server_domain_name_or_IP/
进入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配置成功
如果访问出现 css和js样式不对,以及报403 Fobbien 的错误,则表示nginx user权限不够,需要设置nginx.conf的头部user: root

Django3.0 + nginx + uwsgi 部署的更多相关文章
- 填坑!!!virtualenv 中 nginx + uwsgi 部署 django
一.为什么会有这篇文章 第一次接触 uwsgi 和 nginx ,这个环境搭建,踩了太多坑,现在记录下来,让后来者少走弯路. 本来在 Ubuntu14.04 上 搭建好了环境,然后到 centos7. ...
- nginx + uwsgi 部署 Django+Vue项目
nginx + uwsgi 部署 Django+Vue项目 windows 本地 DNS 解析 文件路径 C:\Windows\System32\drivers\etc 单机本地测试运行方式,调用dj ...
- CentOS7 + Python3 + Django(rest_framework) + MySQL + nginx + uwsgi 部署 API 开发环境, 记坑篇
CentOS7 + Python3 + Django(rest_framework) + MySQL + nginx + uwsgi 部署 API 开发环境 CentOS7 + Python3 + D ...
- Nginx + uWSGI部署中的一些小坑
1.invalid host in upstream报错 重新启动nginx : sudo /etc/init.d/nginx restart 原因是在配置负载均衡nginx.conf配置文件时,发现 ...
- ubuntu+Django + nginx + uwsgi 部署
ubuntu+Django + nginx + uwsgi 部署 0.前期准备 注意:以下几件事都必须在激活虚拟环境下完成 运行以下命令生成项目所需的依赖列表,会在项目根目录生成一个requireme ...
- Python3.6+nginx+uwsgi部署Django程序到阿里云Ubuntu16.04系统
Python3.6+nginx+uwsgi部署Django程序到阿里云Ubuntu16.04系统 这个是写好的Django程序在本地机运行的情况,一个查询接口. 准备工作 1.首先购买一台阿里云的EC ...
- 生产环境使用Nginx+uwsgi部署Django
在本地运行django应用相对来说还是挺方便的,使用自带的runserver启动即可.如果在生产环境部署django,就要多考虑一些问题了.比如静态文件处理,安全,效率等等 在网上找到了不错的部署的教 ...
- Django+Nginx+uWSGI部署
一.介绍 Django的部署可以有多种方式,采用nginx+uwsgi的方式是最常见的一种方式.在这种方式中,将nginx作为服务器前端,接收WEB的所有请求,统一管理请求.nginx把所有静态请求自 ...
- 使用Nginx+Uwsgi部署Python Flask项目
第一次用Flask做Web(也是第一次用Python做Web),在部署的时候遇到了不少问题,现在将过程就下来,供在这方面也有疑惑的人参考.(PS:使用Apache+mod_wsgi部署模式的可以参考另 ...
随机推荐
- (EX)中国剩余定理
中国剩余定理 问题引入: 有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二.问物几何?<孙子算经> 就是计算一个数\(x\)满足\(\begin{cases} x≡2(MOD\ 3) ...
- zjnuSAVEZ (字符串hash)
Description There are eight planets and one planetoid in the Solar system. It is not a well known fa ...
- 迪杰斯特拉+拆点 Deliver the Cake - HDU 6805
题意: t组输入,给你n个点m条边.你需要输出从s点到t点的最短距离,然后是m条边,每条边输入信息为: a,b,c 表示从a点到b点的一个无向边长度为c 每一个点会有一个属性L.R或M 如果a和b一个 ...
- UVALive 7146
Long long ago there is a strong tribe living on the earth. They always have wars and eonquer others. ...
- 洛谷 P1135 奇怪的电梯 (DFS)
题意:有一\(n\)层高的大楼,每层楼都只能在合法情况下上\(x\)层或者下\(x\)层,问你是否能从\(a\)层楼坐电梯到\(b\)层楼,输出最小步数. 题解:直接dfs搜,\(flo\)表示层数, ...
- C++中流操作符<<重载的实现
一.继承fstream后重载其<< 注意:重载函数中不能直接使用参数中的流out,否则会出现递归出错. class CLogStream : public ofstream { publi ...
- CF1462-F. The Treasure of The Segments
题意: 给出n个线段组成的集合,第i个线段用 \(\{l_i, r_i\}\) 表示线段从坐标轴的点\(l_i\)横跨到点\(r_i\).现在你可以删除其中的一些线段,使得剩下的线段组成的集合中至少存 ...
- 秋招C++面试相关总结索引
C++相关 C++ part1 C++ part2 C++ part3 C++ part4 C++ part5 C++ part6 C++ part6.5 C++ part7 C++ part8 C+ ...
- SPOJ SUBST1 New Distinct Substrings(后缀数组 本质不同子串个数)题解
题意: 问给定串有多少本质不同的子串? 思路: 子串必是某一后缀的前缀,假如是某一后缀\(sa[k]\),那么会有\(n - sa[k] + 1\)个前缀,但是其中有\(height[k]\)个和上一 ...
- mark::开源绘图工具graphviz
http://blog.csdn.net/iamljj/article/details/5862930 http://codeforces.com/contest/601/problem/D