0

I'm trying to host django 1.11 application on ubuntu 16.4 server using Nginx. But After running the server I'm getting 504 Gateway Time-out

here is my all port log

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN      3209/redis-server 1
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      15218/nginx -g daem
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1204/sshd
tcp6       0      0 :::9200                 :::*                    LISTEN      28810/java
tcp6       0      0 :::9300                 :::*                    LISTEN      28810/java
tcp6       0      0 :::22                   :::*                    LISTEN      1204/sshd
udp        0      0 0.0.0.0:68              0.0.0.0:*                           963/dhclient

command=/home/ubuntu/miniconda3/envs/ok/bin/gunicorn --access-logfile - --workers 3 --limit-request-line 8000 --bind unix:/home/ubuntu/app/socks/ok.sock configuration.wsgi:application
directory=/home/ubuntu/app/onekkom/backend
user=ubuntu
group=www-data
chmod=664
autostart=true
autorestart=true
stderr_logfile=/var/log/ok_prod_gunicorn.err.log
stdout_logfile=/var/log/ok_prod_gunicorn.out.log

Nginx error.log

*1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 118.179.95.25, server: 18.136.204.142, requ$

2019/07/24 18:13:13 [error] 15221#15221: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 118.179.95.25, server: 18.136.204.142, requ$

2019/07/24 18:20:17 [error] 15485#15485: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 118.179.95.25, server: 18.136.204.142, requ$

any one have any idea about this issue? any sort of help will be appreciated

Zahid Uan Nabi
  • 159
  • 1
  • 1
  • 16
  • possible duplicate check here: https://stackoverflow.com/questions/18740635/nginx-upstream-timed-out-110-connection-timed-out-while-reading-response-hea – Ramy M. Mousa Jul 24 '19 at 18:29
  • I've tried all of given solution but it won't work , Possible reason its django project and the link you gave that is php application – Zahid Uan Nabi Jul 24 '19 at 18:34

1 Answers1

0

Gunicorn times out after 30 seconds by default. It is most likely a gunicorn timeout, and not an nginx timeout. You can increase the timeout in the gunicorn settings. Generally, you may want to do something about the request that is taking over 30 seconds.

http://docs.gunicorn.org/en/stable/settings.html

Sam Creamer
  • 5,187
  • 13
  • 34
  • 49
  • add `--timeout INT` where `INT` is the number of seconds – Sam Creamer Jul 24 '19 at 18:43
  • /home/ubuntu/env/bin/gunicorn --access-logfile - --workers 4 --timeout INT 30 --limit-request-line 8000 --bind unix:/home/ubuntu/onekkom/app.sock backend.configuration.wsgi:application here is it , but its not working – Zahid Uan Nabi Jul 24 '19 at 18:56
  • Just use `--timeout 120`, `INT` is meant to be replaced by the number in that case. Also, 30 is the default, so setting it to 30 will not do anything useful. – Sam Creamer Jul 24 '19 at 19:03
  • after adding '--timeout 120' its showing 502 Bad Gateway – Zahid Uan Nabi Jul 25 '19 at 03:47
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/196955/discussion-between-zahid-uan-nabi-and-sam-creamer). – Zahid Uan Nabi Jul 25 '19 at 05:26
  • Try giving nginx and gunicorn the same timeout window. There's a breakdown in communication between the two. Also, why does the request take so long? – Sam Creamer Jul 25 '19 at 13:43
  • I'm booting celery and webapp at the same time with gunicorn, may be that's why. – Zahid Uan Nabi Jul 25 '19 at 16:17