pyList

Bottle + UWSGI + Nginx 环境搭建过程

这篇文章分享一下Bottle + UWSGI + Nginx 环境搭建过程。

Debian 或 ubuntu 系统

aptitude install uwsgi uwsgi-plugin-python python-bottle nginx

主程序脚本

新建一个python 文件 app.py

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()

运行

python app.py

配置 uwsgi

修改 /etc/uwsgi/apps-available/bottle.ini

[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

ln -s /etc/uwsgi/apps-available/bottle.ini /etc/uwsgi/apps-enabled/bottle.ini
service uwsgi restart

nginx 配置

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

service nginx restart
本文标签: Nginx Bottle UWSGI 搭建 环境
本文网址: https://pylist.com/t/1427427376 (转载注明出处)
如果你有任何建议或疑问可以在下面 留言
发表第一条评论!
验证码图片
相关推荐