title: Django+Nginx+uWSGI = 504 Gateway Time-out with pdf2image
body: <p>I try to run <strong>Django</strong> application using <strong>Nginx</strong>+<strong>uWSGI</strong>.</p>
  <pre><code>sudo apt update
  sudo apt install poppler-utils
  </code></pre>
  <p>I installed <strong>poppler-utils</strong>.</p>
  <p>And my app tries to convert uploaded pdf pages to jpg with <strong>pdf2image</strong> module.
  However, a minute later I received a <strong><code>504 Gateway Time-out</code></strong>.</p>
  <p>It works well when converting a small pdf (335KB) file to jpg.
  However, time-out is received when converting large capacity pdf (6.82MB).</p>
  <ul>
  <li><strong>/etc/nginx/nginx.conf</strong>:</li>
  </ul>
  <pre><code>user www-data;
  worker_processes auto;
  pid /run/nginx.pid;
  include /etc/nginx/modules-enabled/*.conf;
  
  events {
      worker_connections 768;
  }
  
  http {
      client_max_body_size 50M;
      upstream django {
          server unix:/home/ubuntu/myapp/uwsgi.sock;
      }
  
      proxy_send_timeout 300;
      proxy_read_timeout 300;
      proxy_connect_timeout 300;
  
      sendfile on;
      tcp_nopush on;
      tcp_nodelay on;
      keepalive_timeout 65;
      types_hash_max_size 2048;
  
      include /etc/nginx/mime.types;
      default_type application/octet-stream;
  
      access_log /var/log/nginx/access.log;
      error_log /var/log/nginx/error.log;
  
      gzip on;
  
      include /etc/nginx/conf.d/*.conf;
      include /etc/nginx/sites-enabled/*;
  }
  </code></pre>
  <ul>
  <li><strong>/etc/nginx/sites-enabled/default</strong>:</li>
  </ul>
  <pre><code>server {
      listen 80 default server;
      listen [::]:80 default_server;
  
      root /var/www/html;
  
      server _name _;
      
      location / {
          include /etc/nginx/uwsgi_params;
          uwsgi_pass django;
  
          proxy_buffer_size       256k;
          proxy_buffers           16 256k;
          proxy_busy_buffers_size 512k;
      }
  
      ...
  }
  </code></pre>
  <ul>
  <li><strong>uwsgi.ini</strong>:</li>
  </ul>
  <pre><code>[uwsgi]
  chdir=/home/ubuntu/myapp
  module=myapp.wsgi:application
  master=True
  pidfile=/tmp/project-master.pid
  vacuum=True
  max-requests=5000
  daemonize=/home/ubuntu/myapp/django.log
  home=/home/ubuntu/myapp/venv
  virtualenv=/home/ubuntu/myapp/venv
  socket=/home/ubuntu/myapp/uwsgi.sock
  chmod-socket=666
  http-timeout=600
  </code></pre>
  <ul>
  <li><strong>nginx error.log</strong>:</li>
  </ul>
  <pre><code>2022/06/02 17:11:20 [error] 1652#1652: *69 upstream timed out (110: Connection timed out) while reading response header from upstream, client: my_ip, server: _, request: &quot;POST /upload/pdf/url HTTP/1.1&quot;, upstream: &quot;uwsgi://unix:/home/ubuntu/myapp/uwsgi.sock&quot;, host: &quot;my_server_ip&quot;, referrer: &quot;http://my_server_ip/upload/pdf/url&quot;
  </code></pre>
  <p>I don't know what I'm missing.
  Does anyone have an idea of how I can solve this?</p>