这篇文章分享一下Bottle + UWSGI + Nginx 环境搭建过程。
Debian 或 ubuntu 系统
1
aptitude install uwsgi uwsgi-plugin-python python-bottle nginx
主程序脚本
新建一个python 文件 app.py
1
2
3
4
5
6
7
8
from bottle import run, default_app
@route('/')
def home():
return "I am running under nginx and uwsgi!"
if __name__ == "__main__":
run(host='0.0.0.0', port=8080)
else:
application = default_app()
运行
1
python app.py
配置 uwsgi
修改 /etc/uwsgi/apps-available/bottle.ini
1
2
3
4
5
6
7
8
[uwsgi]
socket = /run/uwsgi/app/bottle/socket
chdir = /var/www/bottle
master = true
plugins = python
file = app.py
uid = www-data
gid = www-data
建立软连接后重启uwsgi
1
2
ln -s /etc/uwsgi/apps-available/bottle.ini /etc/uwsgi/apps-enabled/bottle.ini
service uwsgi restart
nginx 配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
upstream _bottle {
server unix:/run/uwsgi/app/bottle/socket;
}
server {
listen [::]:80;
listen 80;
server_name deb.ngx.cc;
root /var/www/bottle;
location / {
try_files $uri @uwsgi;
}
location @uwsgi {
include uwsgi_params;
uwsgi_pass _bottle;
}
}
重启 nginx
1
service nginx restart
本文网址: https://pylist.com/topic/74.html 转摘请注明来源