RequestReadTimeout for virtual host - Apache

CentOS Aug 23, 2017

If your file upload fail to a large file, you might have to adjust the RequestReadTimeout configuration parameter of your Apache httpd web server.

Today, I moved a private development project to a staging area on my VPS. It's an Android application, which need to request data from the backend. It is also possible to upload images to the server. The PHP-Script handles the upload process. One problem was the error: UPLOAD_ERR_PARTIAL

The examples below will edit the configuration on a native host. To keep changes documented, persistent and reproducible, use a configuration management tool.

How to solve it?

This error is in the documentation described as "Value: 3; The uploaded file was only partially uploaded.". But I couldn't find the reason with this description. Let's have a look in the error_log of the Apache httpd.

[...] AH01382: Request body read timeout

I found out, that the RequestReadTimeout was too low for my upload. To modify the timeouts, we have to edit the mod_reqtimeout module.

First, check if the module is installed and activated on the server:

apachectl -M

This list should contain something like "reqtimeout_module (shared)".

I have multiple virtual hosts configured. Because of that, I don't want to set the new values for all hosts, so I couldn't edit /etc/httpd/conf/httpd.conf. Since I have created single configuration files, I had the advantage that the changes will only take effect on this host.

vi /etc/httpd/sites-available/[XYZ].conf

Replace [XYZ] with your configuration file.

We can now easily set the RequestReadTimeout to a required value for the header and body by adding the options. The configuration will allow to receive the headers within 10 and the body within 60 seconds. Setting the value to 0 will set no limit. To have a stable system and reduce the attack surface, try to avoid that.

...
RequestReadTimeout header=10 body=60
...

Just restart the httpd daemon and you are ready to go

apachectl restart

Tested on:

  • OS: CentOS 7
  • Apache: 2.4.6
  • PHP: 7.1.7

Credits:

Tags

Stefan

Howdy! I'm Stefan and I am the main author of this blog. If you want know more, you can check out the 'About me' page.

Impressum | Data Privacy Policy | Disclaimer
Copyright: The content is copyrighted and may not be reproduced on other websites without permission.