django启动uwsgi报错的解决方法


Posted in Python onApril 08, 2018

uwsgi介绍

uWSGI是一个Web服务器,它实现了WSGI协议、uwsgi、http等协议。Nginx中HttpUwsgiModule的作用是与uWSGI服务器进行交换。

要注意 WSGI / uwsgi / uWSGI 这三个概念的区分。

  • WSGI是一种Web服务器网关接口。它是一个Web服务器(如nginx,uWSGI等服务器)与web应用(如用Flask框架写的程序)通信的一种规范。
  • uwsgi是一种线路协议而不是通信协议,在此常用于在uWSGI服务器与其他网络服务器的数据通信。
  • 而uWSGI是实现了uwsgi和WSGI两种协议的Web服务器。
  • uwsgi协议是一个uWSGI服务器自有的协议,它用于定义传输信息的类型(type of information),每一个uwsgi packet前4byte为传输信息类型描述,它与WSGI相比是两样东西。

uwsgi性能非常高

django启动uwsgi报错的解决方法

最近在django启动uwsgi报错的时候,发现了一些错误,下面来一起看看吧

查看uwsgi.log

*** Starting uWSGI 2.0.17 (64bit) on [Thu Apr 5 17:46:15 2018] ***
compiled with version: 4.4.7 20120313 (Red Hat 4.4.7-18) on 05 April 2018 02:08:03
os: Linux-2.6.32-642.6.2.el6.x86_64 #1 SMP Wed Oct 26 06:52:09 UTC 2016
nodename: GDJ_DEV
machine: x86_64
clock source: unix
detected number of CPU cores: 1
current working directory: /xxx/xxx/xxx/xxx
writing pidfile to uwsgi.pid
detected binary path: /xxx/xxx/.virtualenvs/h1/bin/uwsgi
!!! no internal routing support, rebuild with pcre support !!!
chdir() to /xxx/xxx/xxx/xxx
your processes number limit is 100000
your memory page size is 4096 bytes
detected max file descriptor number: 100000
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on 172.21.0.5:8000 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:33522 (port auto-assigned) fd 3
Python version: 3.6.4 (default, Mar 24 2018, 10:32:21) [GCC 4.4.7 20120313 (Red Hat 4.4.7-18)]
Python main interpreter initialized at 0x1ff10d0
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 416880 bytes (407 KB) for 8 cores
*** Operational MODE: preforking+threaded ***
failed to open python file xxx/uwsgi.ini
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 4865)
spawned uWSGI worker 1 (pid: 4866, cores: 2)
spawned uWSGI worker 2 (pid: 4867, cores: 2)
spawned uWSGI worker 3 (pid: 4868, cores: 2)
spawned uWSGI worker 4 (pid: 4869, cores: 2)
spawned uWSGI http 1 (pid: 4870)
--- no python application found, check your startup logs for errors ---
[pid: 4869|app: -1|req: -1/1] 118.26.10.242 () {40 vars in 777 bytes} [Thu Apr 5 17:46:31 2018] GET /user/login/ => generated 21 bytes in 0 msecs (HTTP/1.1 500) 2 headers in 83 bytes (0 switches on core 0)

解决第一个报错,注意操作的先后顺序:

1.卸载uwsgi

pip uninstall uwsgi

#注意此时卸载,pip会有缓存留在系统里

2.安装pcre支持库

yum install pcre pcre-devel pcre-static

3.继续安装uwsgi,不走pip缓存

pip install uwsgi -I --no-cache-dir

#启动uwsgi,已经没有“ !!! no internal routing support, rebuild with pcre support !!! ”报错了

解决第二个报错:

需要在你的uwsgi.ini文件中module指定项目下面的wsgi:

module=xxx.wsgi

#注:xxx为项目名称,startproject那个项目名称,这个错误解决后,下面的访问错误自然而然的就解决了!

附:我的uwsgi.ini配置文件

[uwsgi]
#socket=ip:port       #使用nginx代理请求时配置,直接访问uwsgi使用http方式
http=ip:port
chdir=/xxx/xxx       #项目根目录的绝对路径
wsgi-file=xxx/uwsgi.ini  #项目目录下的uwsgi.ini
module=xxx.wsgi      #指向项目下的wsgi模块
processes=4
threads=2
master=True
py-atuo-reload=1
env=DJANGO_SETTINGS_MODULE=xxx.settings
pidfile=uwsgi.pid
daemonize=uwsgi.log

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,如果有疑问大家可以留言交流,谢谢大家对三水点靠木的支持。

Python 相关文章推荐
python根据经纬度计算距离示例
Feb 16 Python
Windows系统下使用flup搭建Nginx和Python环境的方法
Dec 25 Python
深入理解Django中内置的用户认证
Oct 06 Python
Python入门必须知道的11个知识点
Mar 21 Python
Python常用的json标准库
Feb 19 Python
python机器学习库scikit-learn:SVR的基本应用
Jun 26 Python
python处理RSTP视频流过程解析
Jan 11 Python
Python3列表List入门知识附实例
Feb 09 Python
Python 找出出现次数超过数组长度一半的元素实例
May 11 Python
Python中猜拳游戏与猜筛子游戏的实现方法
Sep 04 Python
详解pycharm配置python解释器的问题
Oct 15 Python
pycharm 多行批量缩进和反向缩进快捷键介绍
Jan 15 Python
python 2.7.14安装图文教程
Apr 08 #Python
详解Python中的动态属性和特性
Apr 07 #Python
简单谈谈Python的pycurl模块
Apr 07 #Python
VSCode下好用的Python插件及配置
Apr 06 #Python
VScode编写第一个Python程序HelloWorld步骤
Apr 06 #Python
在VS Code上搭建Python开发环境的方法
Apr 06 #Python
python装饰器深入学习
Apr 06 #Python
You might like
无线电的诞生过程
2021/03/01 无线电
php中最简单的字符串匹配算法
2014/12/16 PHP
PHP实现GIF图片验证码
2015/11/04 PHP
Dreamweaver jQuery智能提示插件,支持版本提示,支持1.6api
2011/07/31 Javascript
jquery 实现表单验证功能代码(简洁)
2012/07/03 Javascript
js获取当月最后一天实例代码
2013/11/19 Javascript
JavaScript在for循环中绑定事件解决事件参数不同的情况
2014/01/20 Javascript
javascript 处理null及null值示例
2014/06/09 Javascript
JS实现鼠标点击展开或隐藏表格行的方法
2015/03/03 Javascript
javascript实现控制div颜色
2015/07/07 Javascript
jQuery实现有动画淡出效果的二级折叠菜单代码
2015/10/17 Javascript
BootStrap tab选项卡使用小结
2020/08/09 Javascript
一个简易时钟效果js实现代码
2020/03/25 Javascript
vue项目中导入swiper插件的方法
2018/01/30 Javascript
简单了解vue中的v-if和v-show的区别
2019/10/08 Javascript
详解vue父子组件状态同步的最佳方式
2020/09/10 Javascript
实用的 vue tags 创建缓存导航的过程实现
2020/12/03 Vue.js
python简单的函数定义和用法实例
2015/05/07 Python
简述:我为什么选择Python而不是Matlab和R语言
2017/11/14 Python
python通过百度地图API获取某地址的经纬度详解
2018/01/28 Python
使用python对文件中的单词进行提取的方法示例
2018/12/21 Python
pandas修改DataFrame列名的实现方法
2019/02/22 Python
python flask 如何修改默认端口号的方法步骤
2019/07/12 Python
python pygame实现滚动横版射击游戏城市之战
2019/11/25 Python
关于赌博的检讨书
2014/01/08 职场文书
小学生新年寄语
2014/04/03 职场文书
八一建军节演讲稿
2014/09/10 职场文书
高中生逃课检讨书
2014/10/10 职场文书
英文产品推荐信
2015/03/27 职场文书
妈妈别哭观后感
2015/06/08 职场文书
2015年法律事务部工作总结
2015/07/27 职场文书
2016年学习雷锋精神广播稿
2015/12/17 职场文书
2016中学教师读书心得体会
2016/01/13 职场文书
Nginx反向代理及负载均衡如何实现(基于linux)
2021/03/31 Servers
Pytest之测试命名规则的使用
2021/04/16 Python
python批量创建变量并赋值操作
2021/06/03 Python