How To Limit File Upload Size On Apache

by lifeLinux on May 24, 2011

To limit the total size of the HTTP request body sent from the client use LimitRequestBody Directive.

The LimitRequestBody directive allows the user to set a limit on the allowed size of an HTTP request message body within the context in which the directive is given (server, per-directory, per-file or per-location). If the client request exceeds that limit, the server will return an error response instead of servicing the request. The size of a normal request message body will vary greatly depending on the nature of the resource and the methods allowed on that resource. CGI scripts typically use the message body for passing form information to the server. Implementations of the PUT method will require a value at least as large as any representation that the server wishes to accept for that resource.

This directive gives the server administrator greater control over abnormal client request behavior, which may be useful for avoiding some forms of denial-of-service attacks.

This directive specifies the number of bytes from 0 (meaning unlimited) to 2147483647 (2GB) that are allowed in a request body.

For example,if we want to limit upload size to 100k for /var/www/html/uploads, we need to add below commands to .htaccess or httpd.conf.

<Directory "/var/www/html/uploads">
    LimitRequestBody 102400
</Directory>

Finally, restart apache ( if added to httpd.conf ), type the following command as root

# /etc/init.d/httpd graceful

Related Posts:

Previous post:

Next post: