amazon-web-servicesnginxflaskhttp-status-code-504

How do I change the NGINX settings for a AWS Beanstalk Flask app to prevent a 504 TImeout error?


I'm having trouble adjusting the Proxy Connect, Read, and Send settings for NGINX in my Elastic Beanstalk Flask Application. My application does some long calculations so I'm trying to increase the timeout times. Here's what I have:

In the root of my project I have the a directory:

.ebextensions/nginx/conf.d/myconf.conf

The myconf.conf is as follows:

client_max_body_size    10m;
client_body_buffer_size 128k;
proxy_connect_timeout   180;
proxy_send_timeout      180;
proxy_read_timeout      180;

The .conf file is UTF-8. This seems to be what's specified on the AWS site: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-nginx.html

However, I'm still getting a 504 error after 60 seconds. I've tried numerous itterations like placing my .conf file in a .platform/nginx/conf./ directory. No luck there. I've also read over this thread extensively and can't seem to pull out of it what I need: Increasing client_max_body_size in Nginx conf on AWS Elastic Beanstalk

If anybody has any suggestions as to how I should structure this filepath and the myconf.conf file, am I missing headers, quotations, curly brackets?, that would be great. Thank you so much!


Solution

  • I found the solution thanks to this post's answer by Marcin: AWS - Error 504 - Gateway timeout - Flask Application

    The issue was my EB instances was using Amazon Linux 2. This means my .config file need to be located at:

    .platform/nginx/conf.d/

    Inside this directory I made a file called mytimeout.conf (I am also adjusting timeout limits) and have the following in this file:

    keepalive_timeout 240s;
    proxy_connect_timeout 240s;
    proxy_send_timeout 240s;
    proxy_read_timeout 240s;
    fastcgi_send_timeout 240s;
    fastcgi_read_timeout 240s;
    
    client_max_body_size 5M;
    

    I update my amazon app and included the .platform file when I did so and was able to upload a file larger than 1 MB and didn't have timeout errors.