ubuntu NGINX uwsgi https 部署Django 遇到的问题
搞了3天终于把Django成功部署到Ubuntu,记录一下;
引用来自泡泡茶壶:
Ubuntu下的Nginx + Uwsgi + Django项目部署详细流程
前提说明:
Django作为小程序的后端,因小程序的请求到后端的都是https请求,所以Django必须支持https请求
写在前面:
部署Django项目前,先用Django自带服务器运行一下看有没有问题,再部署;否则可能项目本身有问题,却以为是部署不正确导致的
运行命令:python manage.py runserver .....
各种配置:
1、nginx支持https请求
1)项目对象的nginx.conf配置
# the upstream component nginx needs to connect to
upstream django {# unix:///home/breavo/PyWorkSpace/mysite_code_shuffle/config/eshop.sockserver xx.xx.xx.xx:8002; # xx.xx.xx.xx是服务器的ip,若是腾讯云服务器,则是服务器外部ip,这里的ip和端口是和uwsgi通信的方式,所以和uwsgi.ini配置文件中一致
}# configuration of the server
server {# the port your site will be served onlisten 90 ssl; # 监听端口可以是任何端口,但不要和已使用端口冲突# listen 8003;# the domain name it will serve forserver_name indoor.crazymonkey.ml; # 这里可以是域名也可以是本机ip,同上面的xx.xx.xx.xxcharset utf-8;# max upload sizeclient_max_body_size 75M; # adjust to taste# ssl configurationssl on; # 打开了ssl验证,支持https请求ssl_certificate /root/hewenjuan/Indoor_Localization/2446810_www.preciselocation.top.pem; # ssl证书放的位置ssl_certificate_key /root/hewenjuan/Indoor_Localization/2446810_www.preciselocation.top.key; # 使用绝对路径肯定没错啦# Django medialocation /media {alias /root/hewenjuan/Indoor_Localization/media; # your Django project's media files - amend as required,有图片等,}location /static {# alias /path/to/your/mysite/static; # your Django project's static files - amend as requiredalias /root/hewenjuan/Indoor_Localization/static; # 静态文件位置,Django项目admin静态文件}# Finally, send all non-media requests to the Django server.location / {uwsgi_pass django; # 这个就是引用了上面的upstream django配置了# include /home/breavo/PyWorkSpace/mysite_code_shuffle/config/uwsgi_params; # the uwsgi_params file you installedinclude /etc/nginx/uwsgi_params;}
}
说明:用nginx -t命令查看上面nginx文件的正确性
2)项目对应的uwsgi.ini配置
# mysite_uwsgi.ini file
[uwsgi]
socket = xx.xx.xx.xx:8002 # 腾讯云内部ip,端口和nginx.conf配置的Django部分相同
# Django-related settings
# the base directory (full path)
chdir = /root/hewenjuan/Indoor_Localization # Django项目所在目录
# Django's wsgi file
module = Indoor_Localization.wsgi #
# module = config/hello.py:application
wsgi_file = Indoor_Localization/wsgi.py # Django项目wsgi.py所在位置,相对于上面的chdir目录
# wsgi_file = /root/hewenjuan/Indoor_Localization/config/hello.py:application
# the virtualenv (full path)
virtualenv = /root/.pyenv/versions/indoorLocation/bin/python3.6 # python虚拟环境绝对位置
# home = /root/.pyenv
home = /root/.pyenv/versions/indoorLocation# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
# socket = /root/hewenjuan/Indoor_Localization/Indoor_Localization.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum = truestats = %(chdir)/config/uwsgi.status pidfile = %(chdir)/config/uwsgi.pid
# daemonize = %(chdir)/config/uwsgi.log # 开启该字段,uwsgi会在后台运行,日志保存在该文件中,若没有开启该字段,则在前台运行,日志显示在界面上(调试用方便)
# pidfile = %(chdir)/config/uwsgi.pid
#plugins = /root/.pyenv/versions/indoorLocation/bin/python3.6
3)每次修改了Django项目文件代码,都需要重启uwsgi和nginx,所以自己写了个启动文件start.sh
killall -9 uwsgi # 关闭所有uwsgi进程,有时候没有关掉上次的uwsgi进程,启动新的会报错等问题
killall -9 uwsgi # 额,有时候关闭一次会出现没关掉的情况
uwsgi --ini mysite_uwsgi.ini # 启动mysite_uwsgi.ini文件,即启动uwsgi进程
/etc/init.d/nginx restart # 重启nginx进程
说明:启动start.sh命令:sh start.sh
2、uwsgi支持https请求
1)uwsgi.ini配置
# mysite_uwsgi.ini file
[uwsgi]# 2446810_www.preciselocation.top.pem,2446810_www.preciselocation.top.key是ssl证书
https = xx.xx.xx.xx:443,2446810_www.preciselocation.top.pem,2446810_www.preciselocation.top.key # xx.xx.xx.xx是腾讯云内部ip
# Django-related settings
# the base directory (full path)
chdir = /root/hewenjuan/Indoor_Localization
# Django's wsgi file
module = Indoor_Localization.wsgi
# module = config/hello.py:application
wsgi_file = Indoor_Localization/wsgi.py
# wsgi_file = /root/hewenjuan/Indoor_Localization/config/hello.py:application
# the virtualenv (full path)
virtualenv = /root/.pyenv/versions/indoorLocation/bin/python3.6
# home = /root/.pyenv
home = /root/.pyenv/versions/indoorLocation# process-related settings
# master
master = true
# maximum number of worker processes
processes = 10
# the socket (use the full path to be safe
# socket = /root/hewenjuan/Indoor_Localization/Indoor_Localization.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
# clear environment on exit
vacuum = truestats = %(chdir)/config/uwsgi.status pidfile = %(chdir)/config/uwsgi.pid
# daemonize = %(chdir)/config/uwsgi.log
# pidfile = %(chdir)/config/uwsgi.pid
#plugins = /root/.pyenv/versions/indoorLocation/bin/python3.6
遇到的问题:
1、每次退出账号重新登录都会提示,pyenv 不存在了
原因:
方法:命令行输入:source ~/.bashrc;即执行.bashrc文件中的语句(包含 了pyenv初始化语句)
2、nginx权限问题:django admin后台样式不显示,查看nginx错误日志(位置:/var/log/nginx/error.log),显示权限拒绝Permission denied
原因:Django项目下的static文件执行权限不够
方法:打开文件/etc/nginx/nginx.conf,修改 user www-data为user root(root:你目前登录的账号名称,也可能是Ubuntu等其他)
参考qingspace:https://www.cnblogs.com/qingspace/p/6838747.html
3、unavailable modifier requested
原因:没有激活python虚拟环境
方法:输入命令:pyenv activate xx,激活xx环境,xx是你项目所在的python虚拟环境
4、安装项目依赖包:pip install -r requirements.txt,遇到一个问题:安装不成功,界面没有显示不成功
出现下面显示的Successfully ...才表示安装成功
原因:requirements.txt文件中有win_xx的安装包,即有python接入window系统所使用的安装包,类似了win32等,啥除掉即可;
因为有可能写代码使用的是window系统,部署的时候放在了Linux系统
解决方法:删除win32等针对window系统的安装包
转载于:https://www.cnblogs.com/heiao10duan/p/11159524.html
ubuntu NGINX uwsgi https 部署Django 遇到的问题相关推荐
- Ubuntu Nginx uwsgi django 初试
/*************************************************************************************** Ubuntu Ngin ...
- django+nginx+uwsgi项目部署文档整理
django+nginx+uwsgi项目部署文档整理 参考文章:https://blog.csdn.net/qq_42314550/article/details/81805328 一.python安 ...
- Python+Django+Nginx+Uwsgi 详细部署过程(爬坑过程,可以了解各个软件的执行流程,看过)
这个部署,我真的是爬了好久的坑,才爬出来,所以给大家分享一下,避免入坑. 首先我们先了解一下相关知识: wsgi: 一种实现python解析的通用接口标准/协议,是一种通用的接口标准或者接口协议, ...
- 腾讯云CentOS7.2+Django2.2+Python3.7+Nginx+Uwsgi 初学者部署教程
腾讯云CentOS+Django+Python+Nginx+Uwsgi 部署(自用,简单记录) 说明:本人是做前端研发的,最近研究了后台Django框架,并部署到服务的整个流程,为了避免以后忘记,写一 ...
- python前后端分离项目部署_nginx+uwsgi+supervisor部署django前后端分离项目
以下内容为原创,转载请注明出处! 先前一直用的apache部署django项目,查看链接地址:https://www.520pf.cn/article/22.html .这次帮同事用nginx部署服务 ...
- 关于在ubuntu下用docker部署Django卡在 Watching for file changes with StatReloader 不动了 以及 run后无法访问web 的问题
1.问题描述: 用docker部署Django时遇到问题如下: 卡在这里不动了,等了半小时服务也没起来 我的dockerfile如下: 直接启动没有问题: 用exec命令在容器内直接起也没有问题: 2 ...
- Ubuntu nginx+uwsgi部署Django项目
前提条件:首先项目使用一下命令启动成功后,输入公网ip后可以启动成功 python manage.py runserver 0.0.0.0:80 一.阿里云配置安全组 添加8000端口 二.安装配置u ...
- Centos7+nginx+uwsgi来部署我的Django项目
前不久写了个小的博客项目,想着将它部署到服务器上去,因为是第一次部署项目,有很多的东西都不这么懂,走了很多的弯路,现在部署成功了,怕以后忘记了就记录下笔记 首先我的项目结构如下: 关于服务器的远程连接 ...
- Django +nginx + uwsgi + daphne部署
Django 项目用 channels 写了一个实时聊天室(用websocket) .uwsgi对websocket不太友好.所以http的使用uwsgi,websocket使用Daphne . ng ...
最新文章
- Twisted入门教程(3)
- 基于机器学习的捡球机器人设计与实现(探索)第4篇——机械设计)
- 解析全局配置文件的时候,做了什么?
- 分布式文件系统研究-测试-上传文件测试
- 在数据库插入带小数点数据的问题
- unique-substrings-in-wraparound-string(好)
- 【Python】检测字符串的方法
- VBA中常用的字符串处理函数
- UE4C++ Http下载文件
- 黑客X档案的《黑客免杀入门》
- Android 开源控件
- win10家庭版升级到企业版
- 关于图像傅里叶变换得到的频谱图的通俗理解
- aso优化师是什么_来肯云商app官网下载_做ASO优化师,只懂刷榜就够了吗
- JavaScript中getYear,getMonth,getDate()
- Mac垃圾文件清理指南
- Linux系统安装--LInix系统随笔(二)
- 224除以10为什么等于22c语言,C语言 编程练习22
- GPU暗战CPU十年凭什么?
- 数学 -- log