Skip to content

Commit ba7cf42

Browse files
committed
fix deploy.html explaining timeout and max size error messages in nginx
1 parent 4d17708 commit ba7cf42

File tree

1 file changed

+39
-9
lines changed

1 file changed

+39
-9
lines changed

deploy.html

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,20 @@ <h3>Install system fonts (to produce and download the same plots visible on the
352352
</code></pre>
353353
More details <a target="_blank" href="https://unix.stackexchange.com/a/305934">here (opens in new tab)</a>
354354

355+
<h3>Configure maximum request size and maximum timeout errors</h3>
356+
Django does not have a way to do this, and in any case it is better to
357+
configure these settings only in one place, so we do it in the nginx config file:
358+
<div>
359+
<span class="token important">/etc/nginx/sites-available/$DJANGO_PROJECT</span>
360+
</div>
361+
Therein, <code>proxy_read_timeout</code> sets the maximum for processing time
362+
(delegates gunicorn, so if you change this
363+
the timeout set in
364+
<span class="token important">$EGSIM_LOG_DIR/gunicorn.log</span>
365+
<b>that should not be lower than the nginx timeout</b>)
366+
and <code>client_max_body_size</code> sets the maximum size
367+
368+
(a snippet of the nbinx file is also at the bottom of this document).
355369

356370
<h1>Server installation</h1>
357371

@@ -770,24 +784,40 @@ <h3>NGINX</h3>
770784
keepalive_timeout 70;
771785
# certificate (must be configured for https, tutorial not covered here. For non-secure connection, you can comment out the following lines):
772786
ssl_certificate /etc/ssl/certs/egsim.chain.txt; # file is not there by default, to be added
773-
ssl_certificate_key /etc/ssl/private/$DOMAIN.key; # file is not there by default, to be added
774-
ssl_session_cache shared:SSL:10m;
775-
ssl_session_timeout 10m;
776-
location / {
787+
ssl_certificate_key /etc/ssl/private/$DOMAIN.key; # file is not there by default, to be added
788+
ssl_session_cache shared:SSL:10m;
789+
ssl_session_timeout 10m;
790+
791+
location / {
777792
proxy_pass http://localhost:$GUNICORN_PORT;
778-
proxy_read_timeout 180s; # this should match proxy server timeout (gunicorn, uwsgi,...) in the gunicorn service file
793+
# Time limits. Keep them all the same for simplicity. IMPORTANT: when changing these, change also the text in custom_timeout_exceeded (see below)
794+
proxy_connect_timeout 180s; # How long to wait for a connection to the upstream
795+
proxy_send_timeout 180s; # How long to wait for the upstream server to send data
796+
proxy_read_timeout 180s; # How long to wait for the upstream server to respond. It should be >= the proxy server timeout (gunicorn, uwsgi,...). See gunicorn service file
779797
proxy_set_header Host $http_host;
780-
proxy_redirect off;
781-
proxy_set_header X-Forwarded-For $remote_addr;
782-
proxy_set_header X-Forwarded-Proto $scheme;
783-
client_max_body_size 20m;
798+
proxy_redirect off;
799+
proxy_set_header X-Forwarded-For $remote_addr;
800+
proxy_set_header X-Forwarded-Proto $scheme;
801+
client_max_body_size 25M; # max body size, change also @custom_size_limit_exceeded message if you change this
784802
}
785803
location /static/ {
786804
alias /var/cache/$DJANGO_PROJECT/static/;
787805
}
788806
location /media/ {
789807
alias $EGSIM_DATA_DIR/media/;
790808
}
809+
# Return a text response for 413 error, likely it is a flatfile size problem
810+
error_page 413 = @custom_size_limit_exceeded;
811+
# Return a text response for 502 (gunicorn timeout) and 504 (nginx timeout) errors, likely they are timeout problems
812+
error_page 502 504 = @custom_timeout_exceeded;
813+
# Custom location for 404 error response
814+
location @custom_size_limit_exceeded {
815+
return 413 'Data size too large (max 25 Mb allowed). If you uploaded a flatfile, try to remove unnecessary fields (columns) and try again';
816+
}
817+
# Custom location for 500 error response
818+
location @custom_timeout_exceeded {
819+
return 504 'Processing takes too long (max 180 s allowed). If you can, try to decrease the number of models, imts or flatfile records (rows) and try again';
820+
}
791821
}
792822
</code></pre>
793823

0 commit comments

Comments
 (0)