【发布时间】:2012-07-27 02:07:08
【问题描述】:
处理包含多行的 excel 文件时出现错误 502。
使用 Django / Nginx
问题不是文件的重量小于1Mb。
此页面可以正常处理 200 行的文件,当文件有更多行时问题开始,然后页面处理此文件的时间过长。
这是错误:
2012/07/28 14:29:54 [error] 18515#0: *34 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "POST /import/ HTTP/1.1", upstream: "http://127.0.0.1:9000/import/", host: "localhost:8080", referrer: "http://localhost:8080/import/"
我对变量使用了非常大的值,但我一直收到同样的错误。
这是网站的配置:
upstream app_server {
server 127.0.0.1:9000 fail_timeout=3600s;
keepalive 3600s;
}
server {
listen 8080;
client_max_body_size 4G;
server_name localhost;
keepalive_timeout 3600s;
client_header_timeout 3600s;
client_body_timeout 3600s;
send_timeout 3600s;
location /static/ {
root /my path/;
autoindex on;
expires 7d;
}
location /media/ {
root /my path/;
autoindex on;
expires 7d;
}
location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_connect_timeout 3600s;
proxy_send_timeout 3600s;
proxy_read_timeout 3600s;
if (!-f $request_filename) {
proxy_pass http://app_server;
break;
}
}
}
这是全局配置:
user www-data;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
access_log /var/log/nginx/access.log;
sendfile on;
keepalive_timeout 3600s;
tcp_nodelay on;
client_header_timeout 3600s;
client_body_timeout 3600s;
send_timeout 3600s;
proxy_connect_timeout 3600s;
proxy_send_timeout 3600s;
proxy_read_timeout 3600s;
client_max_body_size 200m;
client_body_buffer_size 128k;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
你能给我一些帮助吗?
最好的问候
【问题讨论】:
-
Tbh 你可能应该使用 django-celery 之类的东西将其作为服务器端任务。
-
听起来 Django 处理文件的时间比 nginx 预期的要长,因此它不会等待 gunicorn 返回 Django 响应。 或者它崩溃了。您的 Django 代码是否记录任何异常?假设它是超时,我希望看到 504,而不是 502。
-
upstream prematurely closed connection表示后端出错。 -
好的,感谢您的回复,我将使用 django-celery 使导入过程更加高效。但是我的配置发生了一些奇怪的事情,因为当我使用开发服务器(不使用 nginx)运行 django 时,导入过程需要 3 分钟,而且我没有收到任何错误。然后,我想在收到此错误 502 之前找到一个变量来添加更多处理时间。