How to Limit User File Upload Size in Apache

Apache is a free and open-source cross-platform very popular, secure, efficient and extensible HTTP server. As a server administrator, one should always have greater control over client request behavior, for example the size of...

Spread the love

Apache is a free and open-source cross-platform very popular, secure, efficient and extensible HTTP server. As a server administrator, one should always have greater control over client request behavior, for example the size of files a user can upload and download from a server.

Read Also: 13 Apache Web Server Security and Hardening Tips

This may be useful for avoiding certain kinds of denial-of-service attacks and many other issues. In this short article, we will show how to limit the size of uploads in Apache web server.

The directive LimitRequestBody is used to limit the total size of the HTTP request body sent from the client. You can use this directive to specifies the number of bytes from 0 (meaning unlimited) to 2147483647 (2GB) that are allowed in a request body. You can set it in the context of server, per-directory, per-file or per-location.


For example, if you are permitting file upload to a particular location, say /var/www/example.com/wp-uploads and wish to restrict the size of the uploaded file to 5M = 5242880Bytes, add the following directive into your .htaccess or httpd.conf file.

<Directory "/var/www/example.com/wp-uploads">
LimitRequestBody 5242880
</Directory>

Save the file and reload the HTTPD server to effect the recent changes using following command.

# systemctl restart httpd #systemd
OR
# service httpd restart #sysvinit

From now on, if a user tries to upload a file into the directory /var/www/example.com/wp-uploads whose size exceeds the above limit, the server will return an error response instead of servicing the request.

Reference: Apache LimitRequestBody Directive.

You may also find these following guides for Apache HTTP server useful:

  1. How to Check Which Apache Modules are Enabled/Loaded in Linux
  2. 3 Ways to Check Apache Server Status and Uptime in Linux
  3. How to Monitor Apache Performance using Netdata on CentOS 7
  4. How to Change Apache HTTP Port in Linux

That’s it! In this article, we have explained how to limit the size of uploads in Apache web server. Do you have any queries or information to share, use the comment form below.

Facebook Comments

More Stuff

Fencing and Adding a Failover to Clustering – Part 3 In the previous two guides, we’ve discussed how to install cluster, creating a cluster and adding nodes to the cluster, also we’ve studied how cluster...
How to Install Latest Magento CMS in Ubuntu and Debian Magento is a free, open-source CMS for web-commerce websites, first launched in 2008 and later acquired by eBay, according to W3Techs, Magento is used...
Quick Cash for Your House? Yes, There Are Apps for That If you put your house up for sale, know that it’ll typically be on the market for about a month before you get an offer—an eternity when you’re hosti...
XenServer 7 – Pool Upgrade via CLI and XenCenter Web Interface The first article in this XenServer 7 Series covered how to install/upgrade a single XenServer host. Most XenServer installs are likely to be in a poo...
Spread the love

Posted by News Monkey