通过uwsgi+nginx启动flask的python web程序
通过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 {
listen 8080;
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..2和wusgi wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz tar -xf Python-3.7..tar.xz
cd Python-3.7.
mkdir /usr/local/python372
./configure --prefix=/usr/local/python372
make
make install # 报错
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes' # 解决办法: yum install libffi-devel libffi # 再次编译安装即可
./configure --with-ssl --prefix=/usr/local/python372
make
make install
echo $? # 删除原来的软链,重新建立软连接
# rm -f /usr/local/python3
cd /usr/local
ln -s python372 python3 [root@srv3:/usr/local/python3]# python3 -V
Python 3.7.
# 安装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./ uwsgi-latest.tar.gz
[root@srv3:/usr/local/uwsgi]# cd uwsgi-2.0./
[root@srv3:/usr/local/uwsgi/uwsgi-2.0.]# 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 build time: seconds
*** uWSGI is ready, launch it with ./uwsgi *** # 继续install
# python3 setup.py install [root@srv3:~]# whereis uwsgi
uwsgi: /usr/bin/uwsgi /etc/uwsgi /usr/local/bin/uwsgi /usr/local/uwsgi /opt/uwsgi-2.0.13.1/bin/uwsgi
[root@srv3:~]# uwsgi --version
2.0. # 编写测试文件
[root@srv3:/usr/local/uwsgi/uwsgi-2.0.]# cat testuwsgi.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.]# ./uwsgi --http : --wsgi-file testuwsgi.py
*** Starting uWSGI 2.0. (64bit) on [Wed Jun :: ] ***
compiled with version: 4.4. (Red Hat 4.4.-) on June ::
os: Linux-2.6.-642.6..el6.x86_64 # SMP Wed Oct :: UTC
nodename: srv3.keepvid.com
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores:
current working directory: /usr/local/uwsgi/uwsgi-2.0.
detected binary path: /usr/local/uwsgi/uwsgi-2.0./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
your memory page size is bytes
detected max file descriptor number:
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on : fd
spawned uWSGI http (pid: )
uwsgi socket bound to TCP address 127.0.0.1: (port auto-assigned) fd
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.7. (default, Jun , ::) [GCC 4.4. (Red Hat 4.4.-)]
*** Python threads support is disabled. You can enable it with --enable-threads ***
Python main interpreter initialized at 0x1e8dcd0
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 connections
your mercy for graceful operations on workers is seconds
mapped bytes ( KB) for cores
*** Operational MODE: single process ***
WSGI app (mountpoint='') ready in seconds on interpreter 0x1e8dcd0 pid: (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 (and the only) (pid: , cores: )
[pid: |app: |req: /] 127.0.0.1 () { vars in bytes} [Wed Jun :: ] GET / => generated bytes in msecs (HTTP/1.1 ) headers in bytes ( switches on core ) # 验证
[root@srv3:~]# curl http://127.0.0.1:9000/
Hello World
./configure --with-ssl --prefix=/usr/local/python372
编译的时候一定要添加 --with-ssl (cenos7.x上可以)否则pip3 install -r 安装模块时会报错:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not avail
centos6安装python3.7.x参考 https://www.cnblogs.com/reblue520/p/11103311.html
通过uwsgi+nginx启动flask的python web程序的更多相关文章
- Python Web 程序使用 uWSGI 部署
Python Web 程序使用 uWSGI 部署 WSGI是什么? WSGI,全称 Web Server Gateway Interface,或者 Python Web Server Gateway ...
- 将你的Python Web程序部署到Ubuntu服务器上
在本文记录了我在Ubuntu中部署Flask Web站点的过程, 其中包括用户创建.代码获取.Python3环境的安装.虚拟环境设置.uWSGI启动程序设置,并将Nginx作为前端反向代理.希望对各位 ...
- 使用Flask+uwsgi+Nginx部署Flask正式环境
环境准备 在开始正式讲解之前,我们将首先进行环境准备. Step1:安装Python,pip以及nginx: sudo apt-get update sudo apt-get install pyth ...
- C# 启动 Flask for Python
概览 最近有个需求是通过c#代码来启动 python 脚本.嘿~嘿!!! 突发奇想~~既然可以启动 python 脚本,那也能启动 flask,于是开始着手操作. 先看gif图 准备 因为使用的是.N ...
- 全面解读python web 程序的9种部署方式
转载自鲁塔弗的博客,本文地址http://lutaf.com/141.htm python有很多web 开发框架,代码写完了,部署上线是个大事,通常来说,web应用一般是三层结构 web serve ...
- python web 程序的9种部署方式
python有很多web 开发框架,代码写完了,部署上线是个大事,通常来说,web应用一般是三层结构 Web Server====> Application=====> DB S ...
- Pycharm+Django搭建第一个Python Web程序
1.安装django 无论是Python2.x还是Python3.x版本,都可以使用pip来安装Django.在控制台使用如下命令:pip install django 如: 2.检查dgango是否 ...
- centOS+uwsgi+nginx 部署flask项目,问题记录
用flask做的项目想要部署到centOS系统上,填了一些坑,终于成功了,记录一下遇到的问题: 此次部署主要是按照这个博客进行的 https://www.cnblogs.com/Ray-liang/p ...
- 基于Flask框架的Python web程序的开发实战 <一> 环境搭建
最近在看<Flask Web开发基于Python的Web应用开发实战>Miguel Grinberg著.安道译 这本书,一步步跟着学习Flask框架的应用,这里做一下笔记 电脑只安装一个P ...
随机推荐
- 2018牛客网暑期ACM多校训练营(第一场)E Removal(DP)
题意 给你一个大小为n的数组,你可以删掉数组中的任意m个数,问你在删除m个数之后剩下的数组有多少种.(其中数组的每个数的大小<=k) 分析 显然需要动态规划,而k又很小,所以二维dp没问题. 设 ...
- 错误 1 未能找到类型或命名空间名称“DataPager”(是否缺少 using 指令或程序集引用?)
鄙人在设计器SearchTab.xaml中添加了如下一个分页控件: <sdk:DataPager x:Name="dataPagerPrj" Grid.Row="3 ...
- Linux 用top命令查看CPU和内存使用情况
直接 top 回车 PID:进程的ID USER:进程所有者 PR:进程的优先级别,越小越优先被执行 NInice:值 VIRT:进程占用的虚拟内存 RES:进程占用的物理内存 SHR:进程使用的共享 ...
- SQL Server进阶 SQL优化
找到消耗内存最多的SQL SELECT mg.granted_memory_kb, mg.session_id, t.text, qp.query_plan FROM sys.dm_exec_quer ...
- Chrome 浏览器快捷键
Ø 前言 记录下 Chrome 的快捷键,原文链接:http://www.cnblogs.com/mikalshao/archive/2010/11/03/1868568.html 1. 标 ...
- 十七、文件和目录——minishell(1)
主函数运行要去读取从标准输入或终端上输入的整个命令行,然后再去解析命令行参数,解析出来之后,要将其封装成一个 program,然后再将 program 放入 job 中,然后再去执行 job 中的命令 ...
- Immunity Debugger学习 二
1.Exploit开发 发现漏洞只是一个开始,在你完成利用程序之前,还有很长一段路要走.不过Immunity专门为了这项任务做了许多专门设计,相信能帮你减少不少痛苦.接下来我们开发一些PyComman ...
- vue父组件如何调用子组件的属性或方法
常常我们需要组件的拆分,就涉及到父子调用的关系,那么父组件如何调用子组件的属性和方法呢? 子组件child <template> <div> {{msg}} </div& ...
- python面向对象--私有和继承
一. 私有属性和私有方法 应用场景 在实际开发中,对象的某些属性或方法可能只希望在对象的内部使用,而不希望在外部被访问到 私有属性 就是 对象 不希望公开的属性 (属性即类里面的变量) 私有方法 就是 ...
- javaweb简单的实现文件上传
java代码: // @RequestMapping(value = "/upload.do", method = RequestMethod.POST) @RequestMapp ...