現在djangoで開発している中で502が出る時があり,それは処理するファイルが大きく,実行時間が長い時です。
エラーログは以下の通りで,
errorLog
1upstream prematurely closed connection while reading response header from upstream, client
こちらQiita記事を参考にしたところ,gunicorn側のtimeoutなのではないかと思っています。(アプリ側はdebug=trueですがエラーは出ないです)
そのため,gunicorn.confとnginx.confを以下のように設定しましたが,gunicorn.confの設定でtimeout 3600; を追加するとエラーが出て,またそれ抜きの設定では502になります。
どのようにすれば長い処理でもkillされないtimeoutの設定にできますか?
gunicornConf
1server { 2 listen 80; 3 server_name IPアドレス; 4 keepalive_timeout 3600; 5 timeout 3600; <<この行を追加するとエラーになります 6 location /static { 7 alias /var/www/static; 8 } 9 10 location / { 11 proxy_pass http://127.0.0.1:8000; 12 proxy_set_header Host $http_host; 13 proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; 14 } 15} 16
nginxConf
1user nginx; 2worker_processes auto; 3error_log /var/log/nginx/error.log; 4pid /run/nginx.pid; 5 6# Load dynamic modules. See /usr/share/nginx/README.dynamic. 7include /usr/share/nginx/modules/*.conf; 8 9events { 10 worker_connections 1024; 11} 12 13http { 14 log_format main '$remote_addr - $remote_user [$time_local] "$request" ' 15 '$status $body_bytes_sent "$http_referer" ' 16 '"$http_user_agent" "$http_x_forwarded_for" $request_time'; 17 18 access_log /var/log/nginx/access.log main; 19 20 sendfile on; 21 tcp_nopush on; 22 tcp_nodelay on; 23 keepalive_timeout 3600; 24 proxy_connect_timeout 3600; 25 proxy_send_timeout 3600; 26 proxy_read_timeout 3600; 27 send_timeout 3600; 28 types_hash_max_size 2048; 29 30 include /etc/nginx/mime.types; 31 default_type application/octet-stream; 32 33 # Load modular configuration files from the /etc/nginx/conf.d directory. 34 # See http://nginx.org/en/docs/ngx_core_module.html#include 35 # for more information. 36 include /etc/nginx/conf.d/*.conf; 37 38 server { 39 listen 80 default_server; 40 listen [::]:80 default_server; 41 server_name _; 42 root /usr/share/nginx/html; 43 44 # Load configuration files for the default server block. 45 include /etc/nginx/default.d/*.conf; 46 47 location / { 48 } 49 50 error_page 404 /404.html; 51 location = /40x.html { 52 } 53 54 error_page 500 502 503 504 /50x.html; 55 location = /50x.html { 56 } 57 } 58} 59
回答1件
あなたの回答
tips
プレビュー