Una de las páginas de mi sitio web requiere un cálculo largo en el servidor (~2 minutos). Si ejecuto el sitio web en localhost, funciona bien. Pero en producción cuando ~30 segundos. Aquí está mi sección http de nginx conf:
http { log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 120; types_hash_max_size 2048; include /etc/nginx/mime.types; default_type application/octet-stream; # Load modular configuration files from the /etc/nginx/conf.d directory. # See http://nginx.org/en/docs/ngx_core_module.html#include # for more information. include /etc/nginx/conf.d/*.conf; server { listen 80 default_server; listen [::]:80 default_server; server_name _; root /usr/share/nginx/html; # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_read_timeout 300; proxy_connect_timeout 300; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }Intenté agregar:
fastcgi_read_timeout 300; proxy_read_timeout 300;al final (después de "servidor") pero no hizo nada.
Si obtiene el error 502 Bad Gateway, significa que su servidor de aplicaciones (supongo que es Unicorn de acuerdo con sus etiquetas) está enviando el tiempo de espera y no Nginx, debe aumentar el tiempo de espera en su archivo unicorn.rb en su servidor de producción.
worker_processes 2 listen "/tmp/xxx.socket" ##equal to your proxy read timeout in the Nginx config. timeout 300 pid "/tmp/unicorn.xxx.pid"En el caso de Python Green Unicorn, haga lo siguiente:
NUM_WORKERS=3 TIMEOUT=300 exec gunicorn ${DJANGO_WSGI_MODULE}:application \ --name $NAME \ --workers $NUM_WORKERS \ --timeout $TIMEOUT \ --log-level=debug \ --bind=xxxx \ --pid=$PIDFILE