3

多くの行を含む 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/*;
}

助けてもらえますか?

よろしくお願いします

4

1 に答える 1

2

最良のオプションは、django-celery を使用するようにルーチンを書き直すことですが、迅速な解決策が必要な場合は、次を追加して Nginx のプロキシ パスのタイムアウトをアップグレードしてみてください。

proxy_connect_timeout 300s;
proxy_read_timeout 300s;

/var/nginx/sites-available/[site-config] のこの構成を特定のサイトに追加するか、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/

参考文献:

于 2012-11-10T11:48:50.420 に答える