通过uwsgi+nginx启动flask的python web程序

一般我们启动python web程序的时候都是通过python直接启动主文件,测试的时候是可以的,当访问量大的时候就会出问题
python manage.py

通过wsgi web服务器网关接口规范启动是一种比较好的方式:

web服务器 nginx + uwsgi + flask

原理就是nginx通过代理访问通过uwsgi启动监听在本机的flask程序

1.安装uwsgi模块
# pip install uwsgi
2.通过uwsgi启动flask项目
# 通过http方式启动(推荐)
# uwsgi --http 127.0.0.1:9999 -w user:app

# 通过socket方式启动
uwsgi -s 127.0.0.1:9999 -w user:app
# 主入口需要__init__.py文件
user/__init__.py

#cat /etc/nginx/conf.d/cmdb.conf
server {listen8080;server_name  cmdb;location/{root/home/python/Desktop/51reboot/cmdb/;index  index.html index.htm;proxy_pass http://127.0.0.1:9999;}
}

访问方式是:
http://192.168.3.91:8080 --> uwsgi:9999

centos6.8_x64安装python3.7.2和wusgiwget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xztar -xf Python-3.7.2.tar.xz
cd Python-3.7.2
mkdir /usr/local/python372
./configure --prefix=/usr/local/python372make
make install# 报错from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named'_ctypes'# 解决办法:yum install libffi-devel libffi# 再次编译安装即可./configure --with-ssl --prefix=/usr/local/python372make
make install
echo $?# 删除原来的软链,重新建立软连接
#rm -f /usr/local/python3
cd/usr/localln -s python372 python3[root@srv3:/usr/local/python3]# python3 -V
Python3.7.2# 安装ipython# pip3 install ipython# ln -s /usr/local/python372/bin/ipython3 /usr/sbin/ipython3

[root@srv3:/usr/local/uwsgi]# tar zxf uwsgi-latest.tar.gz
[root@srv3:/usr/local/uwsgi]# cd uwsgi-uwsgi-2.0.18/        uwsgi-latest.tar.gz
[root@srv3:/usr/local/uwsgi]# cd uwsgi-2.0.18/[root@srv3:/usr/local/uwsgi/uwsgi-2.0.18]# python3 uwsgiconfig.py --build################# uWSGI configuration #################kernel=Linux
execinfo=False
ifaddrs=True
locking=pthread_mutex
event=epoll
timer=timerfd
filemonitor=inotify
pcre=True
routing=True
capabilities=False
yaml=embedded
json=False
ssl=True
xml=libxml2
debug=False
plugin_dir=.
zlib=True
ucontext=True
malloc=libc############## end of uWSGI configuration #############
total buildtime: 3seconds*** uWSGI is ready, launch it with ./uwsgi ***# 继续install
# python3 setup.pyinstall[root@srv3:~]# whereisuwsgi
uwsgi:/usr/bin/uwsgi /etc/uwsgi /usr/local/bin/uwsgi /usr/local/uwsgi /opt/uwsgi-2.0.13.1/bin/uwsgi
[root@srv3:~]# uwsgi --version2.0.18# 编写测试文件
[root@srv3:/usr/local/uwsgi/uwsgi-2.0.18]# cattestuwsgi.py
def application(env, start_response):start_response('200 OK', [('Content-Type','text/html')])return [b"Hello World"]# 启动
[root@srv3:/usr/local/uwsgi/uwsgi-2.0.18]# ./uwsgi --http :9000 --wsgi-filetestuwsgi.py*** Starting uWSGI 2.0.18 (64bit) on [Wed Jun 19 02:39:19 2019] ***compiled with version:4.4.7 20120313 (Red Hat 4.4.7-23) on 19 June 2019 07:37:03os: Linux-2.6.32-642.6.2.el6.x86_64 #1 SMP Wed Oct 26 06:52:09 UTC 2016nodename: srv3.keepvid.com
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores:24current working directory:/usr/local/uwsgi/uwsgi-2.0.18detected binary path:/usr/local/uwsgi/uwsgi-2.0.18/uwsgi
uWSGI running as root, you can use--uid/--gid/--chrootoptions*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** WARNING: you are running uWSGI without its master process manager ***your processes number limit is128183your memory page size is4096bytes
detected maxfile descriptor number: 65536lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with--thunder-lock)
uWSGI http bound on :9000 fd 4spawned uWSGI http1 (pid: 927)
uwsgi socket0 bound to TCP address 127.0.0.1:25232 (port auto-assigned) fd 3uWSGI running as root, you can use--uid/--gid/--chrootoptions*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***Python version:3.7.2 (default, Jun 19 2019, 02:23:57)  [GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]*** Python threads support is disabled. You can enable it with --enable-threads ***Python main interpreter initialized at0x1e8dcd0uWSGI running as root, you can use--uid/--gid/--chrootoptions*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***your server socket listen backlog is limited to100connections
your mercyfor graceful operations on workers is 60seconds
mapped72920 bytes (71 KB) for 1cores*** Operational MODE: single process ***WSGI app0 (mountpoint='') ready in 0 seconds on interpreter 0x1e8dcd0 pid: 926(default app)
uWSGI running as root, you can use--uid/--gid/--chrootoptions*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
*** uWSGI is running in multiple interpreter mode ***spawned uWSGI worker1 (and the only) (pid: 926, cores: 1)
[pid:926|app: 0|req: 1/1] 127.0.0.1 () {28 vars in 298 bytes} [Wed Jun 19 02:39:58 2019] GET / => generated 11 bytes in 0 msecs (HTTP/1.1 200) 1 headers in 44 bytes (1 switches on core 0)# 验证
[root@srv3:~]# curl http://127.0.0.1:9000/
Hello World

./configure --with-ssl --prefix=/usr/local/python372
编译的时候一定要添加 --with-ssl 否则pip3 install -r 安装模块时会报错:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not avail

转载于:https://www.cnblogs.com/reblue520/p/7884943.html

通过uwsgi+nginx启动flask的python web程序相关推荐

  1. 篇一、Flask打造 Python Web 开发的灵活框架,实现简易登录。要求有 Python、HTML 和 CSS 基础。

    ⭐ 简介:大家好,我是zy阿二,我是一名对知识充满渴望的自由职业者. ☘️ 最近我沉溺于Python的学习中.你所看到的是我的学习笔记. ❤️ 如果对你有帮助,请关注.点赞,让我们共同进步.有不足之处 ...

  2. python程序部署到tomcat服务器_全面解读python web 程序的9种部署方式

    源地址:http://www.linuxde.net/2013/03/13097.html 全面解读python web 程序的9种部署方式 web server ---->applicatio ...

  3. 02 创建一个简单的Python Web程序应用

    第二章 创建第一个Python Web程序应用 目的:制作一个简单的欢迎网站,熟悉Python Web的基本开发流程以及掌握Django的基本结构和常用命令. Python Web的基本开发流程可以概 ...

  4. python web 程序的9种部署方式

    python有很多web 开发框架,代码写完了,部署上线是个大事,通常来说,web应用一般是三层结构 Web Server====> Application=====> DB Server ...

  5. python模拟登录webspare_全面解读python web 程序的9种部署方式

    python有很多web 开发框架,代码写完了,部署上线是个大事,通常来说,web应用一般是三层结构 web server ---->application -----> DB serve ...

  6. Pycharm+Django搭建第一个Python Web程序

    1.安装django 无论是Python2.x还是Python3.x版本,都可以使用pip来安装Django.在控制台使用如下命令:pip install django 如: 2.检查dgango是否 ...

  7. centOS+uwsgi+nginx 部署flask项目,问题记录

    用flask做的项目想要部署到centOS系统上,填了一些坑,终于成功了,记录一下遇到的问题: 此次部署主要是按照这个博客进行的 https://www.cnblogs.com/Ray-liang/p ...

  8. 基于Flask框架的Python web程序的开发实战 二 项目组织结构

    看到第七章-大型程序的结构,备受打击,搞不清工厂函数.蓝本.单元测试,不理解这些对象/变量怎么传递的,感觉好乱,虽然按照源码都照抄了,还是不理解.... 缓缓先.... 本来网上的Flask的教程就比 ...

  9. 在eclipse启动tomcat运行一个web程序,报java.lang.OutOfMemoryError: PermGen space

    错误如下: 2017-3-20 16:41:14 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() ...

最新文章

  1. NLP数据科学家不会告诉你的残酷事实
  2. [MFC] MFC编译程序,缺少MFC动态链接库的解决
  3. 使用Consul实现服务发现:instance-id自定义(3种方式)
  4. 矩阵快速幂求大斐波那契poj3070(java)
  5. 关于vue搭建项目运行出行的错误问题,简直是大坑啊
  6. tf.div()除法运算
  7. classpath目录
  8. Linux常用文件拷贝方式:scp,rsync,expect
  9. 几个开源项目实体层实现方式比较
  10. ArcGIS Pro中的回归分析浅析(下)地理加权回归工具(GWR)使用小结
  11. VS Code Css格式化插件
  12. 关于谷歌浏览器Google Chrome 打开所有网页都显示“无标题”的解决办法。
  13. phpStudy安装教程
  14. 亿阳信通java开发,北京亿阳信通笔试题java+oracle
  15. Julia学习笔记:使用GLM包进行一元回归分析及模型拟合度检验
  16. 计算机教师的应用计划书,教师信息技术个人提升计划
  17. 牵线搭桥,『桥接模式』
  18. presson绘图练习
  19. android studio导入动态库,OPE体育官方网站-OPE体育官方网站
  20. gcc的ar工具及as汇编编译器入门练习及curses库

热门文章

  1. [JavaScript] 函数同名问题
  2. 设置背景图时防止图片拉伸的解决方法
  3. SQL Tuning Advisor简单使用
  4. MySql4.1.7 + PHP5 + Apache2.0.52(win2003下测试通过)
  5. mysql git下载安装_xshell、python、git、mysql安装(玩阿里云的第二天)
  6. 跟计算机有关的比赛策划,计算机协会“装机大赛”活动策划书
  7. mysql aes encrypt_mysql加密函数aes_encrypt()和aes_decrypt()使用教程
  8. python中a and b什么意思_Python中的a+=b和a=a+b之间的区别是什么?
  9. 计算机学院足球队 英语怎么说,计算机学院举办2018届毕业生足球赛
  10. python history文件_【python之路19】文件操作