python bottle部署g_python bottle服务部署(tornado/ uwsgi+ nginx)

本次通过bottle , tornado, uwsgi+ nginx分别来部署bottle项目

【1】通过bottle自带的服务

先安装bottle框架,通过pip3命令,若没有pip3自行安装

sudo pip3 install bottle

创建myapp.py 文件来测试。

from bottle import get,run

@get("/")

def hello():

return "hello"

run(host="0.0.0.0", port=8080)

输入python3 myapp.py然后浏览器里输入地址

image.png

image.png

通过apache2-utils的ab命令进行压力测试

sudo apt install apache2-utils

ab -n 1000 -c 40 http://192.168.146.128:8080/

image.png

使用bottle自带的run比较脆弱

【2】使用 tornado来进行部署

安装tornado

sudo pip3 install tornado

创建myapp.py 文件来测试。

from bottle import get,run

@get("/")

def hello():

return "hello"

run(host="0.0.0.0", port=8080,server="tornado")

添加server="tornado"后可以自动使用tornado来部署bottle

image.png

进行同样的压力测试

image.png

【3】通过uwsgi+nginx进行部署

编写myapp.py

from bottle import get, default_app

@get("/")

def hello():

return "hello"

application = default_app()

安装uwsgi 和 nginx

sudo apt install uwsgi

sudo apt install nginx

配置uwsgi和nginx

在uwsgi的/etc/uwsgi/apps-available 下创建myapp.ini文件

[uwsgi]

socket = 127.0.0.1:9000

chdir= /home/bo

master = true

plugins= python3

file = myapp.py

uid = www-data

gid= www-data

软连接到上一级目录的/apps-enabled下

ln -s /etc/uwsgi/apps-available/myapp.py /etc/uwsgi/apps-enabled/myapp.py

然后启动uwsgi

sudo service uwsgi start

9000端口已经启动

配置nginx

切换到 /etc/nginx/sites-available/创建配置文件myapp.conf

server{

listen [::]:80;

listen 80;

server_name 192.168.146.128

root /home/bo;

location / {

try_files $uri @uwsgi;

}

location @uwsgi{

include uwsgi_params;

uwsgi_pass 127.0.0.1:9000;

}

}

同样软连接到上一目录下的sites-enabled下

重新启动服务

sudo service nginx restart

sudo service uwsgi restert

查看端口服务

netstat -ntlp

image.png

进行测试:

image.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值