1

I have a simple PHP file upload script that uploads a file. The server consists of 1 nginx reverse proxy and another nginx server (upstream). The problem is that when I try to upload very large files ~ 2GB then I get an error:

504 Gateway Time-out

Here is my reverse proxy configuration:

server {
    listen 80;
    
    server_name upload.mycloudhost.com;

    proxy_buffer_size 1024k;
    proxy_buffers 4 1024k;
    proxy_busy_buffers_size 1024k;
    proxy_connect_timeout       600;
    proxy_send_timeout          600;
    proxy_read_timeout          600;
    send_timeout                600;
    client_body_timeout         600;
    client_header_timeout       600;
    keepalive_timeout           600;
    uwsgi_read_timeout          600;

    location / {
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://localhost:13670;
    }
}

And here is the other nginx server (upstream):

server {
    listen 80;
    
    server_name upload.mycloudhost.com;

    client_max_body_size 80G;
    proxy_buffer_size 1024k;
    proxy_buffers 4 1024k;
    proxy_busy_buffers_size 1024k;
    proxy_connect_timeout       600;
    proxy_send_timeout          600;
    proxy_read_timeout          600;
    send_timeout                600;
    client_body_timeout         600;
    client_header_timeout       600;
    keepalive_timeout           600;
    uwsgi_read_timeout          600;

    root /var/www/mycloudhost;
    index index.php index.html index.htm index.nginx-debian.html;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass php:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
    }

    location / {
        try_files $uri $uri/ =404;
    }
}
  • why the setup with a reverse proxy & the upstream server on the same host? The reverse proxy is forwarding to localhost on port 13670, but the upstream nginx is listening to port 80 ? Could you explain? – Martin Mar 02 '21 at 14:16
  • Because the reverse proxy is on the host itself while the other app is in a docker container (port 13670). The reason is so that the same port could be forwarded to multiple machines depending on the Host header. – Martin Zeltin Mar 02 '21 at 15:15
  • what immediately pops into my eye is that on the upstream nginx, you have set ```client_max_body_size``` to a large value, while on the reverse proxy, you have not... (default seems to be 1m) – Martin Mar 02 '21 at 16:23

0 Answers0