nginx + uwsgi 部署bottle

2017/7/30 posted in  运维

安装

apt-get install  uwsgi uwsgi-plugin-python nginx

配置

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
ln -s /etc/uwsgi/apps-available/bottle.ini /etc/uwsgi/apps-enabled/bottle.ini

nginx

配置文件在 /etc/nginx/conf.d/bottle.conf

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;
    }
}

启动

service uwsgi restart
service nginx restart

问题处理

启动失败

查看uwsgi和nginx的日志,查找原因

  • uwsgi日志: /var/logs/uwsgi/app/
  • nginx日志: /var/logs/nginx/error.log

nginx报连接upstream时权限不足

主要原因是nginx是需要运行在web-data用户和组下,对应的uwsgi的socket文件也需要是该用户权限。

bottle运行时print中文时报错

主要原因是编码问题,暂未跟进处理