502 gateway when uploading big files


When I tried to submit a file > 50MB the console shows me the error 502 (BAD GATEWAY) (using java code and follow the guide to submit files from amazon) Less than 50MB no problem, so after some days looking which could be the possible reason, I already increase de idle time out for my Load Balance to 300, I already update the nginx.conf to the following

#Elastic Beanstalk Nginx Configuration File

user                    nginx;
error_log               /var/log/nginx/error.log warn;
pid                     /var/run/nginx.pid;
worker_processes        auto;
worker_rlimit_nofile    200000;

events {
    worker_connections  1024;

http {
    server_tokens off;

    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    include       conf.d/*.conf;

client_body_buffer_size 850M;
	large_client_header_buffers 4 32k;
    fastcgi_buffers 16 32k;
    fastcgi_buffer_size 32k;
    proxy_buffer_size   128k;
    proxy_buffers   4 256k;
    proxy_busy_buffers_size   256k;
    client_max_body_size 850M;
    proxy_connect_timeout 1000s;
    proxy_send_timeout 1000s;
    proxy_read_timeout 1000s;
 	client_header_timeout 1000s;
    client_body_timeout   1000s;
    keepalive_timeout     1000s;

     map $http_upgrade $connection_upgrade {
        default     "upgrade";
     server {
        listen        80 default_server;
        access_log    /var/log/nginx/access.log main;

        client_header_timeout 60;
        client_body_timeout   60;
        keepalive_timeout     60;
        gzip                  off;
         gzip_comp_level       4;
        gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml applic$

        # Include the Elastic Beanstalk generated locations
        include conf.d/elasticbeanstalk/*.conf;

error from logs 2023/06/01 00:23:32 [error] 15044#15044: *1344 upstream prematurely closed connection while reading response header from upstream, client:, server: , request: "POST /IniciateAssyServlet HTTP/1.1", upstream: "", host: "r-techsconsulting.net", referrer: "https://r-techsconsulting.net/analyst/iniciate-assy.jsp?idTaskCard=8"

also update from t3.micro to R5.large ( I see also that option) but nothing is working always I get that error message on console ( I reload the nginx always after setting something)

can you guys help me ! I'm stuck!

2 Answers

Hi, You can increase nginx file upload size - server { client_max_body_size 8M;

//other lines...

} If you are hosting multiple sites add it to the http context like so;

http { client_max_body_size 8M;

//other lines...

} And also update the upload_max_filesize in your php.ini file so that you can upload files of the same size.

answered 4 months ago
  • hey Mustofa I already update the style code in my question to be more readable, I already have that line in the .conf


Hi, this one may help you in troubleshooting your error: https://repost.aws/knowledge-center/elb-alb-troubleshoot-502-errors

profile pictureAWS
answered 4 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions