centOS7安装FLASK +uwsgi +nginx 配置

参考了很多这个兄弟的博客     uwsgi + nginx 发布 - 逆欢 - 博客园  

FLASK项目中的uwsgi配置,配置的http方式

安装项目的依赖

安装项目依赖到虚拟环境中.首先的激活虚拟环境:

source /home/testenv/bin/activate

一.http 启动

撰写uwsgi配置 ,把配置文件命名为uwsgi.ini

[uwsgi]
http=0.0.0.0:5000
;socket = 81.71.70.7:5000
;virtualenv = /root/py38_env     #支持http+socket两种方式,
chdir =/root/xxxxxxx/flask-celery
module = app
# 配置项目目录
wsgi-file=/root/xxxxx/xxxx/app.py
callable=app
processes = 4
threads = 4
buffer-size = 32768
# 开启master, 将会多开一个管理进程, 管理其他服务进程
master = true
# 退出的时候清空环境变量
vacuum = true
;py-autoreload=1
;daemonize =%(chdir)/uwsgi.log
;thunder-lock = true
#防止惊群
harakiri = 60
#超时时间(秒)
vacuum = true
;touch-logreopen = %(chdir)/logs/touchforlogrotate  # 日志分割监听文件

验证下是否正常启动

uwsgi --ini uwsgi.ini 

启动

[uWSGI] getting INI configuration from uwsgi.ini
*** Starting uWSGI 2.0.20 (64bit) on [Fri Mar  4 23:06:52 2022] ***
compiled with version: 4.8.5 20150623 (Red Hat 4.8.5-44) on 01 March 2022 01:05:51
os: Linux-3.10.0-1127.19.1.el7.x86_64 #1 SMP Tue Aug 25 17:23:54 UTC 2020
nodename: VM-1-34-centos
machine: x86_64
clock source: unix
pcre jit disabled
detected number of CPU cores: 1
current working directory: /root/flask-celery-hjw/flask-celery
detected binary path: /root/py38_env/bin/uwsgi
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
chdir() to /root/flask-celery-hjw/flask-celery
your processes number limit is 15075
your memory page size is 4096 bytes
 *** WARNING: you have enabled harakiri without post buffering. Slow upload could be rejected on post-unbuffered webservers *** 
detected max file descriptor number: 100001
lock engine: pthread robust mutexes
thunder lock: disabled (you can enable it with --thunder-lock)
uWSGI http bound on 0.0.0.0:5000 fd 4
uwsgi socket 0 bound to TCP address 127.0.0.1:43206 (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.1 (default, Jul 29 2021, 02:34:47)  [GCC 4.8.5 20150623 (Red Hat 4.8.5-44)]
Python main interpreter initialized at 0xded360
uWSGI running as root, you can use --uid/--gid/--chroot options
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** 
python threads support enabled
your server socket listen backlog is limited to 100 connections
your mercy for graceful operations on workers is 60 seconds
mapped 1094880 bytes (1069 KB) for 16 cores
*** Operational MODE: preforking+threaded ***
定时任务1
定时任务2
WSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0xded360 pid: 23094 (default app)
mountpoint  already configured. skip.
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 master process (pid: 23094)
spawned uWSGI worker 1 (pid: 23098, cores: 4)
spawned uWSGI worker 2 (pid: 23099, cores: 4)
spawned uWSGI worker 3 (pid: 23101, cores: 4)
spawned uWSGI worker 4 (pid: 23102, cores: 4)
spawned uWSGI http 1 (pid: 23103)

关闭  

杀死uwsgi

kill -9 继承的pid

nginx的相关配置

进入 vi /etc/nginx/nginx.conf文件   

http {

        server {
        listen 80 ;
        access_log  /usr/local/nginx/logs/access.log  ;
        error_log   /usr/local/nginx/logs/error.log ;
   # server {

        location / {
                include uwsgi_params ;
        #       include /usr/local/nginx/conf/uwsgi_params ;

                proxy_pass http://81.71.70.7:5000 ;
        #       uwsgi_pass 81.71.70.7:5000 ;
        }
    }



}

uwsgi_pass: 服务的主机和端口

listen — 表示监听的端口

server_name — 表示服务名称(有域名可以换成域名)

location :接收请求

include uwsgi_params :固定写法

80端口的监听 

 重启 nginx 

nginx -s reload 

访问日志和错误日志在access.log 和error.log中   

就可以正常访问了  ,直接输入地址 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值