2012-07-28 2 views
3

여러 행이있는 Excel 파일을 처리 할 때 오류 502가 발생합니다. 문제는 파일의 무게 아니다 장고/Nginx에많은 행이있는 Excel 파일 처리시 오류 502 발생

를 사용

는 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/*; 
} 

수 너 나 좀 도와 줘?

안부

+3

TBH 당신이 쇼 uld는 아마 django-celery와 같은 서버 측 작업이 될 것입니다. –

+1

Django와 같은 소리는 nginx가 예상하는 것보다 파일을 처리하는 데 오랜 시간이 걸리기 때문에 gunicorn이 장고 응답을 반환 할 때까지 기다리지 않습니다. ** 아니면 ** 추락하고 있습니다. 장고 코드가 예외를 기록합니까? 타임 아웃이라고 가정하면 502가 아닌 504를 볼 수 있습니다. –

+1

'업스트림 조기 폐쇄 연결 '은 백엔드쪽에 오류가 있음을 의미합니다. – VBart

답변

2

최선의 선택이 장고 - 셀러리를 사용하는 루틴을 재 작성하지만 짧은 솔루션을 원하는 경우 추가 Nginx에있는 프록시 패스에 대한 시간 제한을 업그레이드 시도 할 수 :

proxy_connect_timeout 300s; 
proxy_read_timeout 300s; 

nginx에서 제공하는 모든 사이트에서 시간 초과를 늘리려면/var/nginx/sites-available/[site-config]의 특정 설정을이 사이트 또는 /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/ 

참고 :

관련 문제