简体   繁体   中英

Nginx can't handle files 10+ mb file upload

I have a production and nonproduction environment both with the same YAML configuration

In the production environment, uploading a file over around 10+- mb results in a 403 error generated by nginx. Anything under will result in a successful file upload

whilst in the non prod environment, we are able to upload files that follow the limit given by our config, up to 1gb

below is a snippet of the important annotations being added

    nginx.ingress.kubernetes.io/client-body-buffer-size: 1000m
    nginx.ingress.kubernetes.io/client-max-body-size: 1000m
    nginx.ingress.kubernetes.io/fastcgi-read-timeout: "600"
    nginx.ingress.kubernetes.io/fastcgi-send-timeout: "600"
    nginx.ingress.kubernetes.io/idle-timeout: 600s
    nginx.ingress.kubernetes.io/modsecurity-snippet: SecRuleRemoveByID 949110
    nginx.ingress.kubernetes.io/proxy-body-size: 1000m
    nginx.ingress.kubernetes.io/proxy-connect-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-next-upstream-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-read-timeout: "600"
    nginx.ingress.kubernetes.io/proxy-send-timeout: "600"
    nginx.ingress.kubernetes.io/rewrite-target: /$1```

By default you can upload only 1 MB in Nginx and if you upload more than that it will throw some error. If you want to increase size the across the site please add below line client_max_body_size 50M If you want to limit only for HTTPS requests but not HTTP requests you need to add client_max_body_size 50M to the server block that listens to port 443 but not the server block that listens to some other port number. In the same way you can add it for particular directive/URL location /uploads { ... client_max_body_size 50M; }

After the above steps you need to check the syntax of your updated config file by below command:

$ sudo nginx -t If there are no errors run the following commands to restart:

$ sudo service nginx reload #debian/ubuntu

$ systemctl restart nginx #redhat/centos

Please refer to the documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM