uwsgi+flask
(基础环境:centos7+python3.8)
[root@localhost untitled2]# pip3 list Package Version ------------ ------- appdirs 1.4.3 click 7.1.1 distlib 0.3.0 filelock 3.0.12 Flask 1.1.1 itsdangerous 1.1.0 Jinja2 2.11.1 MarkupSafe 1.1.1 pip 20.0.2 setuptools 41.2.0 six 1.14.0 uWSGI 2.0.18 Werkzeug 1.0.0
学习uwsgi+flask启动方式
1 flask创建最简单的框架
2 编写uwsgi.ini
[uwsgi] http=:5001 wsgi-file=/root/PycharmProjects/untitled2/app.py callable=app
3 启动uwsgi
[root@localhost untitled2]# uwsgi uwsgi.ini [uWSGI] getting INI configuration from uwsgi.ini *** Starting uWSGI 2.0.18 (64bit) on [Thu Mar 26 19:14:48 2020] *** compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-39) on 26 March 2020 10:57:26 os: Linux-3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 nodename: localhost.localdomain machine: x86_64 clock source: unix pcre jit disabled detected number of CPU cores: 1 current working directory: /root/PycharmProjects/untitled2 detected binary path: /opt/app/python/bin/uwsgi uWSGI running as root, you can use --uid/--gid/--chroot options *** 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 is 7144 your memory page size is 4096 bytes detected max file descriptor number: 4096 lock engine: pthread robust mutexes thunder lock: disabled (you can enable it with --thunder-lock) uWSGI http bound on 0.0.0.0:5001 fd 4 spawned uWSGI http 1 (pid: 26723) uwsgi socket 0 bound to TCP address 127.0.0.1:37301 (port auto-assigned) fd 3 uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** Python version: 3.8.2 (default, Mar 25 2020, 19:39:49) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] *** Python threads support is disabled. You can enable it with --enable-threads *** Python main interpreter initialized at 0x11432e0 uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** your server socket listen backlog is limited to 100 connections your mercy for graceful operations on workers is 60 seconds mapped 72920 bytes (71 KB) for 1 cores *** Operational MODE: single process *** WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x11432e0 pid: 26722 (default app) uWSGI running as root, you can use --uid/--gid/--chroot options *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** *** uWSGI is running in multiple interpreter mode *** spawned uWSGI worker 1 (and the only) (pid: 26722, cores: 1)
4 浏览器访问:检查是否成功
后续
1 flask+uwsgi+nginx
参考:https://www.cnblogs.com/xingxia/p/python_nginx_uwsgi.html
(分清楚是socket模式,还是http模式. 第一次配置nginx,参考的是一篇nginx中socket模式连接的。我前面uwsgi中配置的是http模式。两个配置没有一致。如果第一次配置成功了,我就不会继续去看另外一种配置方式。纸上得来终觉浅,绝知此事要躬行)
nginx扩展学习:https://www.cnblogs.com/chenyanbin/p/12521296.html
2 flask+uwsgi+nginx+supervisor
pipy: https://pypi.org/project/supervisor/ 目前不支持python 3.8。 (文章当时是3月底写的,7月5日更新发现连接里面已经支持python3.8. 看来跟新速度可以)
3 docker+flask+wusgi+nginx+supervisor