我正在使用基于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秒钟(由于数据的处理时间.)
配置:
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;
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的“非线程安全”特性,处理挂起导致超时.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。