收到错误502处理与许多行Excel文件时(Getting error 502 when proce

2019-07-30 16:34发布

处理与许多行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/*;
}

你能给我一些帮助?

最好的祝福

Answer 1:

最好的办法是重新编写程序来使用Django,芹菜,但如果你想有一个快速的解决方案,你可以尝试通过添加升级为代理通在Nginx的超时:

proxy_connect_timeout 300s;
proxy_read_timeout 300s;

你应该,如果你想增加nginx的服务的所有网站的超时上的/ var / nginx的/网站可用/ [站点配置]这个配置添加到特定网站或/var/nginx/nginx.conf。

如果您正在使用gunicorn,您必须添加--timeout = 300为好。 例:

gunicorn_django -D -b 127.0.0.1:8901 --workers=2 --pid=/var/webapp/campus.pid --settings=settings.production --timeout 300 --pythonpath=/var/webapp/campus/

参考文献:

  • http://wiki.nginx.org/HttpProxyModule#proxy_connect_timeout

  • http://reinout.vanrees.org/weblog/2011/11/24/apache-nginx-gunicorn-timeout.html

  • Gunicorn Nginx的超时问题



文章来源: Getting error 502 when processing an excel file with many rows
标签: django nginx