bottle + nginx:连接到上游时,connect()失败(111:连接被拒绝)

时间:2019-07-24 13:38:09

标签: python nginx centos bottle

我的nginx错误日志中收到以下大量错误:

connect() failed (111: Connection refused) while connecting to upstream

我的应用程序否则可以正常工作,如果我尝试从日志中访问URL,它们在浏览器中都显示为ok,但我仍想找到这些错误的来源。

我已经尝试在我的nginx配置中启用保持活动状态,但是它没有任何改变。

location / {
        proxy_pass         http://localhost:8080;
        proxy_http_version 1.1;
        proxy_set_header   Connection "";
    }

我的服务器正在运行CentOS 7.6,Python 2.7.5,瓶子0.13-dev和nginx 1.12.2。

这是一个使用gevent服务器的Bottle Web应用程序:

bottle.run(app=myapp, host='0.0.0.0', port=8080, debug=False, quiet=True, reloader=False, server='gevent')

这是我的Nginx配置:

server {
    listen 80;
    server_name *****;
    proxy_set_header X-Forwarded-For $remote_addr;

    root  /usr/local/*****;
    client_max_body_size 128M;

    location /static {
    }

    location /protected {
        internal;
    }

    location / {
        proxy_pass         http://localhost:8080;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/*****/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/*****/privkey.pem; # managed by Certbot
    # include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot

    if ($scheme != "https") {
        return 301 https://$host$request_uri;
    } # managed by Certbot
}

是否仅仅是gevent和Bottle无法足够快地处理请求并给出临时连接被拒绝的错误?我应该尝试使用uWSGI之类的其他服务器还是使用某些nginx代理优化?

1 个答案:

答案 0 :(得分:0)

我在Nginx上使用bottle并且工作正常,我用gunicorn wsgi服务器处理了负载,并且效果很好,我尝试使用

python3 app.py

很好,我建议您使用此代码来设置瓶子服务器

import bottle
from bottle import run

if __name__ == '__main__':
    run(host='localhost', port=8080)
application = bottle.default_app()

我认为最好用/这样完成代理通行证

location / {
    proxy_pass         http://localhost:8080/;
}