Help Center/ Web Application Firewall/ User Guide/ Access Management/ Advanced Settings/ Configuring a Timeout for Connections Between WAF and a Website Server
Updated on 2026-10-10 GMT+08:00

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.

Figure 1 WAF forwarding requests to origin servers.
  • 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

  • Cloud CNAME access: This function is only supported in professional and enterprise editions.
  • Cloud load balancer access: This function is not supported. When ELB is used for access, the timeout duration is controlled by the ELB listener and origin server. WAF does not hold the TCP connection of the client and cannot independently control the connection timeout threshold.
  • Dedicated mode: This function is supported.

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

  • This function cannot be disabled once it is configured.

Configuring a Timeout

You can configure the timeout duration by referring to Procedure, Configuration Suggestions and Verification Methods.

Procedure

  1. Log in to the WAF console.
  2. Click in the upper left corner and select a region or project.
  3. (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.
  4. In the navigation pane on the left, choose Assets > Protected Objects.
  5. On the Protected Objects page, click the target domain name.
  6. 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

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.

  • Connection timeout: 15 to 20
  • Write timeout: 10 to 15
  • Read timeout: 15 to 20

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.

  • Connection timeout: 20 to 30
  • Write timeout: 20 to 30
  • Read timeout: 30 to 60

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.

  • Connection timeout: 20 to 30
  • Write timeout: 30 to 60
  • Read timeout: 30 to 40

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.

  • Connection timeout: 30 to 40
  • Write timeout: 25 to 35
  • Read timeout: 35 to 50

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.

  • Default settings:
    • Connection timeout: 30
    • Write timeout: 180
    • Read timeout: 180
  • Adjustment scenarios:
    • Service heartbeat interval > 60s: You are advised to set the read/write timeout to 2 to 3 times the heartbeat interval.
    • High-concurrency persistent connection scenario (a large number of resident connections on a single node): You are advised to set the read timeout to a smaller value (for example, 60s to 90s) to accelerate the reclamation of zombie connections and prevent resource occupation.
    • Scenarios where backend faults need to be quickly detected or a quick failover is required: You are advised to set the connection timeout to 5s to 10s.

Verification Methods

After the preceding configurations are complete, you can view the configured Back-to-Origin Request timeouts in the Timeout Settings area.

To modify the timeout that has been configured, click next to Connection Timeout, Read Timeout (s), or Write Timeout (s).