TEST杂记:flask+uwsgi+nginx

2024-05-06 19:48
文章标签 nginx test uwsgi flask 杂记

本文主要是介绍TEST杂记:flask+uwsgi+nginx,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

一、搭建web环境(flask+uwsgi+nginx)

  • 安装flask
  • 安装和配置uwsgi
  • 配置nginx

1.创建虚拟环境

pip3 install --upgrade virtualenv
cd /var
mkdir web2
cd web2
virtualenv -p python3 .env进入虚拟环境安装flask
source .env/bin/activate
pip3 install flask
deactivate  

写一个简单的测试程序

from flask import Flaskapp = Flask(__name__)@app.route("/helloWorld")
def helloWorld():return "Hello World"if __name__ == '__main__':app.run(host='0.0.0.0', port=8787, debug=True)

2.安装和配置uwsgi

1. 在安装uwsgi之前,需要安装python-dev,否则可能会安装失败

apt-get
yum install python3.6-dev()
pip3 install uwsgi
find / -name uwsgi
ln -s /usr/local/python3/bin/uwsgi /usr/bin/uwsgi

2. 创建uwsgi.ini配置文件

[uwsgi]
chdir=/www/wwwroot/test # 工程目录
home=/www/wwwroot/test/.env # 虚拟环境目录
module=test  # 启动flask应用的文件名,不用加.py
callable=app # 应用名,与我们hell
master=true
processes=2 # worker的进程个数
chmod-socket=666
logfile-chmod=644
procname-prefix-spaced=test # uwsgi的进程名称前缀,启动后可通过ps -ef | grep test查找到这个进程
py-autoreload=1 #py文件修改,自动加载,也就是设置热启动了
#http=0.0.0.0:8080 #监听端口,测试时使用vacuum=true # 退出uwsgi是否清理中间文件,包含pid、sock和status文件
socket=%(chdir)/uwsgi/uwsgi.sock # socket文件,配置nginx时候使用
stats=%(chdir)/uwsgi/uwsgi.status # status文件,可以查看uwsgi的运行状态
pidfile=%(chdir)/uwsgi/uwsgi.pid # pid文件,通过该文件可以控制uwsgi的重启和停止
daemonize=%(chdir)/uwsgi/uwsgi.log # 设置后台模式,然后将日志输出到uwsgi.log。当调试时,可先注释掉此内容
*************************************************************************************************************************************************************
[uwsgi]
chdir=/www/wwwroot/test
home=/www/wwwroot/test/.env
module=test
callable=app
master=true
processes=2
chmod-socket=666
logfile-chmod=644
procname-prefix-spaced=test
py-autoreload=1
#http=0.0.0.0:8080vacuum=true
socket=%(chdir)/uwsgi/uwsgi.sock
stats=%(chdir)/uwsgi/uwsgi.status
pidfile=%(chdir)/uwsgi/uwsgi.pid
daemonize=%(chdir)/uwsgi/uwsgi.log

3.创建其它相关文件

mkdir uwsgi
cd uwsgi
touch file uwsgi.pid uwsgi.sock uwsgi.status uwsgi.log

常用命令:

uwsgi --ini uwsgi.ini             # 启动
uwsgi --reload uwsgi.pid          # 重启
uwsgi --stop uwsgi.pid            # 关闭

配置nginx.conf

vi nginx.conf

location / {include uwsgi_params;uwsgi_pass unix:/www/wwwroot/test/uwsgi/uwsgi.sock;
}

这篇关于TEST杂记:flask+uwsgi+nginx的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/965215

相关文章

Windows下Nginx的安装及开机启动

1、将nginx-1.16.1.zip解压拷贝至D:\web\nginx目录下。 2、启动Nginx,两种方法: (1)直接双击nginx.exe,双击后一个黑色的弹窗一闪而过。 (2)打开cmd命令窗口,切换到nginx目录下,输入命令 nginx.exe 或者 start nginx ,回车即可。 3、检查nginx是否启动成功。 直接在浏览器地址栏输入网址 http://lo

nginx介绍及常用功能

什么是nginx nginx跟Apache一样,是一个web服务器(网站服务器),通过HTTP协议提供各种网络服务。 Apache:重量级的,不支持高并发的服务器。在Apache上运行数以万计的并发访问,会导致服务器消耗大量内存。操作系统对其进行进程或线程间的切换也消耗了大量的CPU资源,导致HTTP请求的平均响应速度降低。这些都决定了Apache不可能成为高性能WEB服务器  nginx:

论文翻译:ICLR-2024 PROVING TEST SET CONTAMINATION IN BLACK BOX LANGUAGE MODELS

PROVING TEST SET CONTAMINATION IN BLACK BOX LANGUAGE MODELS https://openreview.net/forum?id=KS8mIvetg2 验证测试集污染在黑盒语言模型中 文章目录 验证测试集污染在黑盒语言模型中摘要1 引言 摘要 大型语言模型是在大量互联网数据上训练的,这引发了人们的担忧和猜测,即它们可能已

web群集--nginx配置文件location匹配符的优先级顺序详解及验证

文章目录 前言优先级顺序优先级顺序(详解)1. 精确匹配(Exact Match)2. 正则表达式匹配(Regex Match)3. 前缀匹配(Prefix Match) 匹配规则的综合应用验证优先级 前言 location的作用 在 NGINX 中,location 指令用于定义如何处理特定的请求 URI。由于网站往往需要不同的处理方式来适应各种请求,NGINX 提供了多种匹

nginx长连接的问题

转自: http://www.360doc.com/content/12/1108/17/1073512_246644318.shtml

NGINX轻松管理10万长连接 --- 基于2GB内存的CentOS 6.5 x86-64

转自:http://blog.chinaunix.net/xmlrpc.php?r=blog/article&uid=190176&id=4234854 一 前言 当管理大量连接时,特别是只有少量活跃连接,NGINX有比较好的CPU和RAM利用率,如今是多终端保持在线的时代,更能让NGINX发挥这个优点。本文做一个简单测试,NGINX在一个普通PC虚拟机上维护100k的HTTP

CRtmpServer转推流到Nginx Rtmp及SRS(SimpleRtmpServer)的经历

转自:http://blog.csdn.net/fengyily/article/details/42557841 本人一直用的是CRtmpServer服务,在CRtmpServer服务中根据自已的想法也加入了许多功能,如通过http接口来加载配置等,苦于不支持HLS,自已添加ts分片水平又有限,思来想去决定借助SimpleRtmpServer的HLS功能。说干就干,马上查找相关资源

由Lua 粘合的Nginx生态环境

转自:http://blog-zq-org.qiniucdn.com/pyblosxom/oss/openresty-intro-2012-03-06-01-13.html -- agentzh tech-club.org 演讲听录 免责聲明 Lua 粘合的 Nginx 生态环境 2.1. openresty 2.2. 配置小语言 2.3. ngx_drizzle 2.4.

Nginx高性能分析

Nginx 是一个免费的,开源的,高性能的 HTTP 服务器和反向代理,以及 IMAP / POP3 代理服务器。Nginx 以其高性能,稳定性,丰富的功能,简单的配置和低资源消耗而闻名。本文从底层原理分析 Nginx 为什么这么快! Nginx 的进程模型 Nginx 服务器,正常运行过程中: 多进程:一个 Master 进程、多个 Worker 进程。Master 进程:管理 Work

Golang test编译使用

创建文件my_test.go package testsimport "testing"func TestMy(t *testing.T) {t.Log("TestMy")} 通常用法: $ go test -v -run TestMy my_test.go=== RUN TestMyTestMy: my_test.go:6: TestMy--- PASS: TestMy (0.