如果正文太大,Nginx / Uwsgi / Flask POST会超时
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了如果正文太大,Nginx / Uwsgi / Flask POST会超时,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2060字,纯文字阅读大概需要3分钟。
内容图文
![如果正文太大,Nginx / Uwsgi / Flask POST会超时](/upload/InfoBanner/zyjiaocheng/963/82af69d47068442a9b8b8a7d98ef2711.jpg)
我正在使用基于https://github.com/tiangolo/uwsgi-nginx-flask-docker/tree/master/python3.6的dockerimage.我正在运行一个接受POST的python应用程序,对json主体进行一些处理,然后返回一个简单的json响应.像这样的帖子:
curl -H "Content-Type: application/json" -X POST http://10.4.5.168:5002/test -d '{"test": "test"}'
工作良好.但是,如果我发布了一个更大的json文件,我会得到一个504:Gateway Timeout.
curl -H "Content-Type: application/json" -X POST http://10.4.5.168:5002/test -d @some_6mb_file.json
我觉得Nginx和Uwsgi之间的通信存在问题,但我不确定如何修复它.
编辑:我跳入docker容器并手动重新启动nginx以获得更好的日志记录.我收到以下错误:
2018/12/21 20:47:45 [error] 611#611: *1 upstream timed out (110:
Connection timed out) while reading response header from upstream,
client: 10.4.3.168, server: , request: “POST
/model/refuel_verification_model/predict HTTP/1.1”, upstream:
“uwsgi://unix:///tmp/uwsgi.sock”, host: “10.4.3.168:5002”
从容器内部开始,我开始使用我的Flask应用程序的第二个实例,在没有Nginx和Uwsgi的情况下运行,它运行良好.响应大约需要5秒钟(由于数据的处理时间.)
配置:
/etc/nginx/nginx.conf:
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
daemon off;
/etc/nginx/conf.d/nginx.conf:
server {
listen 80;
location / {
try_files $uri @app;
}
location @app {
include uwsgi_params;
uwsgi_pass unix:///tmp/uwsgi.sock;
}
location /static {
alias /app/static;
}
}
/etc/nginx/conf.d/upload.conf:
client_max_body_size 128m;
client_body_buffer_size 128m;
解决方法:
Tensorflow存在问题.我在应用程序初始化期间加载了tensorflow模型,然后尝试使用它.由于Web服务器完成的线程和Tensorflow的“非线程安全”特性,处理挂起导致超时.
内容总结
以上是互联网集市为您收集整理的如果正文太大,Nginx / Uwsgi / Flask POST会超时全部内容,希望文章能够帮你解决如果正文太大,Nginx / Uwsgi / Flask POST会超时所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。