安装uwsgi

本文介绍了如何安装uWSGI并使用pip3,以及启动uWSGI服务的命令。接着展示了创建uWSGI配置文件的步骤,包括设置入口模块、进程数和线程数等参数。随后,文章讲解了如何启动和检查uWSGI进程。最后,配置Nginx作为反向代理服务器,连接到uWSGI,以实现Flask应用的部署。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装uWSGI

pip3 install uwsgi

启动命令

/usr/local/python3/bin/uwsgi --socket 0.0.0.0:8889 --workers run_server:app_server --master --processes 4 --threads 2 --stats 0.0.0.0:9191

在项目目录下新建

[uwsgi]

# web应用的入口模块名称

module = run_server:app

# 启动主进程

master = true

# 说明要启动5个子进程处理请求

processes = 3

# 程序内启用的application变量名

callable = app

# flask程序的启动文件,通常在本地是通过运行

wsgi-file = run_server.py

# 项目目录

chdir = /root/PythonWorkSpace/myproject

# 启动程序时所使用的ip和端口号

socket = 127.0.0.1:8001

# uwsgi日志路径

logto = /tmp/boom.log

chmod-socket = 660

vacuum = true

# 获取uwsgi统计信息的服务地址

stats = 127.0.0.1:9191

# uwsgi进程的pid,用于以后的stop和reload

pidfile = uwsgi.pid

buffer-size = 6553600

启动

uwsgi --ini myproject.ini

待验证

部署flask+uwsgi_nginx

原flask启动文件不需要修改,是什么样就是什么样

然后启动uwsgi/usr/local/python3/bin/uwsgi --socket 0.0.0.0:8889 --workers run_server:app_server --master --processes 4 --threads 2 --stats 0.0.0.0:9191

启动后ps -ef 查看进程,会有一个主进程,4个子进程

然后启动nginx

nginx配置文件如下

#user nobody;

worker_processes 4;

#error_log logs/error.log;

#error_log logs/error.log notice;

#error_log logs/error.log info;

#pid logs/nginx.pid;

events {

worker_connections 1024;

}

http {

include mime.types;

default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '

# '$status $body_bytes_sent "$http_referer" '

# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;

#tcp_nopush on;

#keepalive_timeout 0;

keepalive_timeout 65;

#gzip on;

upstream backend {

server 127.0.0.1:8889;

}

server {

listen 80;

server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

# location / {

# proxy_pass http://backend;

# root html;

# index index.html index.html;

#}

location / {

include uwsgi_params;

uwsgi_pass backend; #监听的ip和端口号

#uwsgi_pass 127.0.0.1:8889; #监听的ip和端口号

uwsgi_param UWSGI_PYHOME /usr/local/python3; #pyathon环境

uwsgi_param UWSGI_CHDIR /tool_chain; #项目地址

uwsgi_param UWSGI_SCRIPT run_server:app_server; #web应用的入口模块名称

}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html

#

error_page 500 502 503 504 /50x.html;

location = /50x.html {

root html;

}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80

#

#location ~ \.php$ {

# proxy_pass http://127.0.0.1;

#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

#location ~ \.php$ {

# root html;

# fastcgi_pass 127.0.0.1:9000;

# fastcgi_index index.php;

# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

# include fastcgi_params;

#}

# deny access to .htaccess files, if Apache's document root

# concurs with nginx's one

#

#location ~ /\.ht {

# deny all;

#}

}

# another virtual host using mix of IP-, name-, and port-based configuration

#

#server {

# listen 8000;

# listen somename:8080;

# server_name somename alias another.alias;

# location / {

# root html;

# index index.html index.htm;

# }

#}

# HTTPS server

#

#server {

# listen 443 ssl;

# server_name localhost;

# ssl_certificate cert.pem;

# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;

# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;

# ssl_prefer_server_ciphers on;

# location / {

# root html;

# index index.html index.htm;

# }

#}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

张凯的工作室

给我一块,我替你解决问题

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值