Nextcloud Upload Error 413, a fix

I've been running Nextcloud for about two years now on various OS' and with differing databases (Nginx or Apache). Over the last few weeks I've been hitting a wall with uploading from both the Mac and iOS clients and the upload option from the webpage itself; I've been getting the dreaded Upload Error 413. Here's what happened, and my fix.

About two weeks ago I ran into an issue with my web server running Ghost and I ended up having to wipe and reinstall Ubuntu 18.04 and Ghost 2.15. When I did that I failed to take into consideration my reverse proxy settings, I didn't copy 'em.

With Nextcloud installed on a separate server I need to enable a reverse proxy (RP) on my web server which is pulling port 80 and 443 for all four of my servers. My RP looked (past tense) like such

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name cloud.ryanerickson.com;

    #Log storage
   # access_log /var/log/nginx/cloud.domain.access.log;
   # error_log /var/log/nginx/cloud.domain.error.log;

    #SSL Configurations
    ssl on;
    ssl_certificate /etc/letsencrypt/nextcloud/cert.pem;
    ssl_certificate_key /etc/letsencrypt/nextcloud/privkey.pem;
   # ssl_stapling on;
   # ssl_stapling_verify on;

    location / {

        add_header Front-End-Https       on;
        proxy_headers_hash_max_size      512;
        proxy_headers_hash_bucket_size   64;
        proxy_set_header                 Host $host;
        proxy_set_header                 X-Forwarded-Proto $scheme;
        proxy_set_header                 X-Real-IP $remote_addr;
        proxy_set_header                 X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_request_buffering          off;
        # whatever the IP of your cloud server is
        proxy_pass                       https://192.168.1.224;
    }
}

The above worked great for everything except uploading files beyond about four-megabytes. The fix? Add client_max_body_size 0; to the file. Below  is the whole file with the added call (note, the zero (0) makes the upload size open ended without a size limit). They look close, but under proxy_request_buffering I've added our new line of client_max_body_size at line 27 below.

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name cloud.ryanerickson.com;

    #Log storage
   # access_log /var/log/nginx/cloud.domain.access.log;
   # error_log /var/log/nginx/cloud.domain.error.log;

    #SSL Configurations
    ssl on;
    ssl_certificate /etc/letsencrypt/nextcloud/cert.pem;
    ssl_certificate_key /etc/letsencrypt/nextcloud/privkey.pem;
   # ssl_stapling on;
   # ssl_stapling_verify on;

    location / {

        add_header Front-End-Https       on;
        proxy_headers_hash_max_size      512;
        proxy_headers_hash_bucket_size   64;
        proxy_set_header                 Host $host;
        proxy_set_header                 X-Forwarded-Proto $scheme;
        proxy_set_header                 X-Real-IP $remote_addr;
        proxy_set_header                 X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_request_buffering          off;
        client_max_body_size             0;
        # whatever the IP of your cloud server is
        proxy_pass                       https://192.168.1.224;
    }
}

That's it. Now, restart nginx, sudo service nginx restart, and the error should be gone. Upload away and good luck!

Show Comments

Get the latest posts delivered right to your inbox.