Configuring a Timeout for Connections Between WAF and a Website Server
In the cloud CNAME or dedicated access mode, WAF functions as a web application protection gateway. It needs to handle the response process from WAF to the origin server. You can configure a timeout for this key step in the process. If the response time exceeds the configured threshold, WAF terminates the process and returns an error code. This prevents long-term request blocking and unexpected resource usage.
How It Works
WAF timeout settings include the following:
- WAF-to-Server Connection Timeout: timeout for WAF and the origin server to establish a TCP connection.
- Write Timeout: Timeout set for WAF to send a request to the origin server. If the origin server does not receive a request within the specified write timeout, the connection times out.
- Read Timeout: Timeout set for WAF to read responses from the origin server. If WAF does not receive any response from the origin server within the specified read timeout, the connection times out.
Figure 1 shows the three steps for WAF to forward requests to an origin server.
- The timeout for connections from a browser to WAF is 120 seconds. The value varies depending on your browser settings and cannot be changed on the WAF console.
- The default timeout for connections between WAF and your origin server is 30 seconds. You can customize this timeout. If you are using a dedicated WAF instance or the standard, professional or enterprise edition cloud WAF instance, you can configure connection timeout, read timeout, and write timeout.
Constraints
| Function | Constraint |
|---|---|
| Access mode restrictions |
|
| Region constraints | Supported regions: CN North-Beijing1, CN North-Beijing2, CN North-Beijing4, CN East-Shanghai1, CN East-Shanghai2, CN South-Guangzhou, CN South-Shenzhen, CN Southwest-Guiyang1, CN-Hong Kong, AP-Singapore, and AP-Jakarta |
| Other |
|
Configuring a Timeout
You can configure the timeout duration by referring to Procedure, Configuration Suggestions and Verification Methods.
Procedure
- Log in to the WAF console.
- Click
in the upper left corner and select a region or project. - (Optional) If you have enabled the enterprise project function, in the upper part of the navigation pane on the left, select your enterprise project from the Filter by enterprise project drop-down list. Then, WAF will display the related security data in the enterprise project on the page.
- In the navigation pane on the left, choose .
- On the Protected Objects page, click the target domain name.
- In the row containing Timeout Settings, configure the timeout duration.
- Back-to-Origin Request: When you configure this field for the first time, click Quick Configuration. In the Back-to-Origin Request dialog box, complete the following configurations and click OK.
Table 1 Back-to-origin request parameters Parameter
Description
Timeout Impact
Example Value
WAF-to-Origin Connection Timeout (s)
The connection timeout indicates the maximum time required for WAF to establish a TCP connection with the origin server. The default value is 30 seconds. The value ranges from 0 to 180 seconds.
- If the value is too small, normal requests may be incorrectly identified as connection failures when the network is unstable or your service is deployed across regions. As a result, error code 504 is returned.
- If the value is too large, when the origin server breaks down and becomes unreachable, it takes longer for a single request to be identified as a failure. As a result, abnormal connections remain occupied for a longer period.
30
Read Timeout (s)
The read timeout indicates the maximum time required for WAF to read a response from the origin server. The default value is 180 seconds. The value ranges from 0 to 3,600 seconds.
- If the value is too small, the silent interval of slow interfaces, complex queries, or persistent connections may easily exceed the value. As a result, requests will fail (usually with a 504 error) or persistent connections will be interrupted.
- If the value is too large, a single connection occupies WAF and origin server resources longer when the origin server responds slowly or the connection is suspended abnormally. This may affect the processing capabilities of the instance.
180
Write Timeout (s)
The write timeout indicates the maximum time required for WAF to send a request to the origin server. The default value is 180 seconds. The value ranges from 0 to 3,600 seconds.
- If the value is too small, a large request body upload or poor network may cause the process to stall. As a result, the upload fails (504 is returned in most cases).
- If the value is too large, abnormal connections may be stacked in the sending channel for a long time. This increases resource usage.
180
- Back-to-Origin Request: When you configure this field for the first time, click Quick Configuration. In the Back-to-Origin Request dialog box, complete the following configurations and click OK.
Configuration Suggestions
| Application | Workload Characteristics | Back-to-Origin Timeout (s) |
|---|---|---|
| General scenarios, such as static websites and small APIs, with a request body of less than 10 MB | The origin server processes requests quickly and the network is stable. A time range from 10 to 20 seconds is reserved for client timeout to avoid misjudgment. |
|
| Dynamic scenarios, such as database APIs and complex logic, with a request body of 10 MB to 50 MB | The origin server takes a long time to process requests. The client timeout must cover the maximum read timeout and a buffer must be reserved. |
|
| Large request scenarios, such as file upload and large form submission, with a request body of 50 MB or larger | The request body is parsed for a long time after being transmitted. The client timeout must match the maximum timeout value of the request body, or the upload may be interrupted. |
|
| Cross-region or weak network scenarios, such as mobile access and cross-region deployment | The network latency is high. More buffers are reserved for client timeout to adapt to weak network transmission fluctuation. |
|
| Persistent connections | A persistent connection service establishes bidirectional or unidirectional streaming channels after a successful handshake. The connection can last from several minutes to several hours, and the data exchange frequency is not fixed. There may be long idle intervals due to network fluctuations or long processing times on the origin server. Typically, a heartbeat mechanism is used to maintain the connection. |
|
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot

