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 相关文章推荐
在ironpython中利用装饰器执行SQL操作的例子
May 02 Python
Python中pygame的mouse鼠标事件用法实例
Nov 11 Python
Python实现计算最小编辑距离
Mar 17 Python
python读取oracle函数返回值
Jul 18 Python
Python中实现最小二乘法思路及实现代码
Jan 04 Python
Python中一些深不见底的“坑”
Jun 12 Python
搭建python django虚拟环境完整步骤详解
Jul 08 Python
python字符串切割:str.split()与re.split()的对比分析
Jul 16 Python
Python倒排索引之查找包含某主题或单词的文件
Nov 13 Python
pycharm设置python文件模板信息过程图解
Mar 10 Python
解决Pytorch自定义层出现多Variable共享内存错误问题
Jun 28 Python
python 统计代码耗时的几种方法分享
Apr 02 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
第十节 抽象方法和抽象类 [10]
2006/10/09 PHP
php 中英文语言转换类代码
2011/08/11 PHP
fgetcvs在linux的问题
2012/01/15 PHP
linux下使用crontab实现定时PHP计划任务失败的原因分析
2014/07/05 PHP
2014最热门的24个php类库汇总
2014/12/18 PHP
php跨服务器访问方法小结
2015/05/12 PHP
WIFI万能钥匙密码查询接口实例
2015/09/28 PHP
PHP实现权限管理功能示例
2017/09/22 PHP
如何使用jQUery获取选中radio对应的值(一句代码)
2013/06/03 Javascript
js获取input标签的输入值实现代码
2013/08/05 Javascript
jquery统计用户选中的复选框的个数
2014/06/06 Javascript
JS函数this的用法实例分析
2015/02/05 Javascript
Javascript中call,apply,bind方法的详解与总结
2016/12/12 Javascript
BootStrapTable服务器分页实例解析
2016/12/20 Javascript
ReactNative踩坑之配置调试端口的解决方法
2017/07/28 Javascript
JS小球抛物线轨迹运动的两种实现方法详解
2017/12/20 Javascript
AjaxUpLoad.js实现文件上传功能
2018/03/02 Javascript
详解JS取出两个数组中的不同或相同元素
2019/03/20 Javascript
配置一个vue3.0项目的完整步骤
2019/04/26 Javascript
详解babel升级到7.X采坑总结
2019/05/12 Javascript
基于JS实现table导出Excel并保留样式
2020/05/19 Javascript
[01:00:12]2018DOTA2亚洲邀请赛 4.7 淘汰赛 VP vs LGD 第一场
2018/04/09 DOTA
python访问mysql数据库的实现方法(2则示例)
2016/01/06 Python
python3 读写文件换行符的方法
2018/04/09 Python
Python批处理更改文件名os.rename的方法
2018/10/26 Python
Python实现合并两个有序链表的方法示例
2019/01/31 Python
python 整数越界问题详解
2019/06/27 Python
python rsa实现数据加密和解密、签名加密和验签功能
2019/09/18 Python
python实现的分析并统计nginx日志数据功能示例
2019/12/21 Python
Numpy 理解ndarray对象的示例代码
2020/04/03 Python
纽约和芝加哥当天送花:Ode à la Rose
2019/07/05 全球购物
Stührling手表官方网站:男女高品质时尚手表的领先零售商
2021/01/07 全球购物
企业治理工作自我评价
2013/09/26 职场文书
干部个人对照检查材料
2014/08/25 职场文书
个人公司授权委托书范本
2014/10/12 职场文书
2016年优秀团支部事迹材料
2016/02/26 职场文书