uwsgi + nginx + flask + emperor:(104:由对等方重置连接),同时从上游读取响应头

时间:2018-01-23 11:41:51

标签: python nginx flask uwsgi

我正在使用uwsgi运行一个烧瓶应用程序并使用nginx来提供内容。

vassal ini文件:

[uwsgi]
chdir = /var/www/html/PyNLP/
;emperor = /var/www/html/PyNLP/
module = nltk_endpoint:app
master = true
processes = 5
socket = /tmp/PyNLP.sock
virtualenv = /var/www/html/PyNLP/nltkenv
mount = /PyNLP=nltk_endpoint:app
chmod-socket = 666
uid = www-data
gid = www-data
vacuum = true
die-on-term = true
enable-threads = true
;harakiri = 300
;buffer-size=65535

项目包含在/ var / www / html / PyNLP中,包含文件nltk_endpoint.py以及上面的.ini文件

现在,当我在没有皇帝的情况下运行它时:

uwsgi --ini PyNLP.ini --manage-script-name

当我尝试通过邮递员POST请求访问此烧瓶API时似乎工作正常。 URL如下所示:

http://myIP:81/PyNLP/spellCheck

第一部分/ PyNLP是烧瓶应用程序的安装点,最后一部分/ spellCheck是项目中的应用程序路径:

@app.route("/spellCheck", methods=["POST"])
def spellCheck():
    req = request.get_json()
    resp = jsonify(spell_check(req['text']))
    return resp

nginx配置如下:

location = /PyNLP { rewrite ^ /PyNLP/; }
location /PyNLP { try_files $uri @PyNLP; }
location @PyNLP {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        #try_files $uri $uri/ =404;
        include uwsgi_params;
        uwsgi_pass unix:/tmp/PyNLP.sock;
}

没有皇帝,这很好用。但是当我尝试使用时:

uwsgi --emperor emperor/emperor.ini --manage-script-name

我在postman上的url路径出现了404错误

Emperor ini档案:

[uwsgi]
;emperor-tyrant = true
;emperor = %dvassals
;emperor-pidfile = %demperor.pid
;emperor-stats = %demperor.stat.sock
;vassals-include = %dvassals-default.ini
;touch-logrotate = %p
;touch-reload = %p
;touch-reload = %dvassals-default.ini
;log-date = true
;log-truncate = true
;logto = 
emperor = /var/www/html/PyNLP/
;chdir = /var/www/html/PyNLP/
;mount = /PyNLP=nltk_endpoint:app
;buffer-size=65535
uid = www-data
gid = www-data
vacuum = true
die-on-term = true

此请求的uwsgi日志是:

[pid: 9812|app: 0|req: 1/1] 111.125.198.234 () {48 vars in 841 bytes} [Tue Jan 23 10:49:17 2018] POST /PyNLP/spellCheck => generated 233 bytes in 5 msecs (HTTP/1.1 404) 2 headers in 72 bytes (1 switches on core 0)announcing my loyalty to the Emperor...

和nginx / error.log as:

*43 recv() failed (104: Connection reset by peer) while reading response header from upstream, client: 111.125.198.234, server: _, request: "POST /PyNLP/spellCheck HTTP/1.1", upstream: "uwsgi://unix:/tmp/PyNLP.sock:", host: "XX.XX.XX.XX:81"

关于stackoverflow的类似问题建议更改ini文件中的缓冲区大小,这没有帮助以及验证是否正确处理了帖子正文,我认为也没问题,因为它适用于POST请求就好了没有皇帝。我怀疑它可能是一个mount或url路径问题或权限问题,但无法弄清楚为什么这不会与皇帝合作。有任何想法吗?提前谢谢。

0 个答案:

没有答案