Does the Nginx configuration not allow file uploads?

Hello,
The Nginx configuration is:

# CORS Origin Mapping (keep your existing map)
map $http_origin $cors_origin {
    default "";
    "~^http://(localhost:3000|localhost:3001)(:[0-9]+)?$" $http_origin;
    "~^http://172\.20\.2\.58(:[0-9]+)?$" $http_origin;
}
server {
    listen 80;
    server_name 172.20.2.58 localhost;
    # Security headers (keep existing)
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-Content-Type-Options "nosniff" always;
    root /home/docki/real/portal/public;
    index index.php index.html;
    
     # Increase max upload size (adjust as needed)
    client_max_body_size 100M;
    client_body_buffer_size 128k;
    client_body_temp_path /var/lib/nginx/body_temp;
    
    # Timeout settings for large uploads
    client_body_timeout 300s;
    client_header_timeout 300s;
    keepalive_timeout 300s;
    send_timeout 300s;

    # =====================
    # First App (Port 3000 - Root)
    # =====================
    location / {
        location /branch {
            # Handled in the next section
        }
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_buffering off;
        proxy_request_buffering off;
    }
    location /_next/static {
        proxy_pass http://127.0.0.1:3000/_next/static;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        expires 1y;
        add_header Cache-Control "public, immutable, max-age=31536000";
    }
    # =====================
    # Second App (Port 3001 - Branch)
    # =====================
    location /branch {
        proxy_pass http://127.0.0.1:3001/branch;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_redirect http://127.0.0.1:3001/branch /branch;
        proxy_redirect / /branch/;
    }
    location /branch/_next/static {
        proxy_pass http://127.0.0.1:3001/branch/_next/static;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
        expires 1y;
        add_header Cache-Control "public, immutable, max-age=31536000";
    }
    location /branches {
        proxy_pass http://127.0.0.1:3000/branches;
    }
    # =====================
    # UPDATED API Handling
    # =====================
    location ~ ^/api(/|$) {
        root /home/docki/real/portal/public;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME $document_root/index.php;
        include fastcgi_params;
        # Security/headers
        fastcgi_param HTTP_HOST $host;
        fastcgi_param X-Real-IP $remote_addr;
        fastcgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
        # CORS
        add_header 'Access-Control-Allow-Origin' $cors_origin always;
        add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
        add_header 'Access-Control-Allow-Headers' 'X-Requested-With, Content-Type, Authorization' always;
        add_header 'Access-Control-Allow-Credentials' 'true' always;
        if ($request_method = 'OPTIONS') {
            return 204;
        }
    }
    # =====================
    # PHP Fallback
    # =====================
    location ~ \.php$ {
        root /home/docki/real/portal/public;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_param HTTP_HOST $host;
        fastcgi_param X-Real-IP $remote_addr;
        fastcgi_param X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    # =====================
    # Error Handling
    # =====================
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /404.html {
        internal;
        root /usr/share/nginx/html;
    }
    location = /50x.html {
        internal;
        root /usr/share/nginx/html;
    }
    # =====================
    # Security
    # =====================
    location ~ /\.(?!well-known).* {
        deny all;
        access_log off;
        log_not_found off;
    }
    location ~ /\.ht {
        deny all;
    }
}

When I try to upload a file to the site, the following error is displayed:

Upload

The Nginx report is as follows:

2025/06/02 03:51:55 [warn] 24869#24869: *203 a client request body is buffered to a temporary file /var/lib/nginx/body/0000000005, client: 172.21.50.67, server: 172.20.2.58, request: "POST /api/waxGuards/1 HTTP/1.1", host: "172.20.2.58", referrer: "http://172.20.2.58/waxGuards"

Is there a problem with the Nginx configuration or is this an error on the back-end side?

Thank you.

Not totally sure, but the error is actually a warning that NGINX is buffering. It shows that NGINX successfully received the body request and buffered it. However, I can’t tell (and it doesn’t show) what happened after it passed it on.

I do not see anything wrong in the NGINX configuration. I suggest you might want to look at the Laravel logs and also make sure php.ini also has the approprate limits.

So likely a back-end problem.

1 Like

To add to what @davemc said, you are getting an Axios error. Axios is a JS API library so the core issue lies in whatever JS your backend runs. There might be some other NGINX error too, but the first step is to fix the JS backend.

2 Likes