Nginx Error 413

前端 未结 3 1178
迷失自我
迷失自我 2021-02-04 06:11

When I try to upload a file to my site, I\'m getting the Nginx \"413 Request Entity Too Large\" error, however in my nginx.conf file I\'ve already explicitly stated the max size

相关标签:
3条回答
  • 2021-02-04 06:58

    My setup was:

    php.ini

    ...
    upload_max_filesize = 8M
    ...
    

    nginx.conf

    ...
    client_max_body_size 8m;
    ...
    

    The nginx showed the error 413 when it was uploaded.

    Then I had an idea: I will not let nginx show the error 413, client_max_body_size set to a value greater than upload_max_filesize, thus:

    php.ini

    ...
    upload_max_filesize = 8M
    ...
    

    nginx.conf

    ...
    client_max_body_size 80m;
    ...
    

    What happened?

    When you upload smaller than 80MB nginx will not display the error 413, but PHP will display the error if the file is up to 8MB.

    This solved my problem, but if someone upload a file larger than 80MB error 413 happens, nginx rule.

    0 讨论(0)
  • 2021-02-04 07:06

    Not knowing the version of your nginx build and what modules it was built with makes this tough, but try the following:

    1. Copy your client_max_body_size 300M; line into the location / { } part of your vhost config. I'm not sure if it's overriding the default (which is 1 MB) properly.

    2. Are you using nginx_upload_module? If so make sure you have the upload_max_file_size 300MB; line in your config as well.

    0 讨论(0)
  • 2021-02-04 07:11

    I also add that you could define it in the *.php location handler

    location ~ ^/([a-z,0-9]+)\.php$ {
    

    Being the "lower" one in the cascading level, it would be an easy way to see if the problem comes from your nginx config or modules.

    It sure doesn't come from PHP because the 413 error "body too large" is really a NGinx error.

    0 讨论(0)
提交回复
热议问题