

**推出 的新主控台體驗 AWS WAF**

您現在可以使用更新後的體驗，在主控台的任何位置存取 AWS WAF 功能。如需詳細資訊，請參閱[使用 主控台](https://docs.aws.amazon.com/waf/latest/developerguide/working-with-console.html)。

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# OR 規則陳述式
<a name="waf-rule-statement-type-or"></a>

OR 規則陳述式結合了巢狀陳述式與OR邏輯，因此其中一個巢狀陳述式必須符合，OR陳述式才能相符。這至少需要兩個巢狀陳述式。

例如，如果您想要封鎖來自特定國家/地區的請求或包含特定查詢字串的請求，您可以建立 OR陳述式，並在其中巢狀化一個國家/地區的地理比對陳述式，以及查詢字串的字串比對陳述式。

如果您想要封鎖*不是*來自特定國家/地區或包含特定查詢字串的請求，您可以修改先前的OR陳述式，將地理比對陳述式巢狀在NOT陳述式內的一個層級。此巢狀層級需要您使用 JSON 格式，因為主控台僅支援一個巢狀層級。

## 規則陳述式特性
<a name="or-rule-statement-characteristics"></a>

**可巢狀** – 您可以巢狀化此陳述式類型。

**WCUs** – 取決於巢狀陳述式。

## 尋找此規則陳述式的位置
<a name="or-rule-statement-where-to-find"></a>
+ 主控台上的**規則建置器** – **如果請求**，請選擇**至少符合其中一個陳述式 (OR)**，然後填入巢狀陳述式。
+ **API** – [OrStatement](https://docs.aws.amazon.com/waf/latest/APIReference/API_OrStatement.html)

**範例**  
下列清單顯示使用 OR來結合其他兩個陳述式。如果其中一個巢狀OR陳述式相符，則陳述式為相符。

```
{
  "Name": "neitherOfTwo",
  "Priority": 1,
  "Action": {
    "Block": {}
  },
  "VisibilityConfig": {
    "SampledRequestsEnabled": true,
    "CloudWatchMetricsEnabled": true,
    "MetricName": "neitherOfTwo"
  },
  "Statement": {
    "OrStatement": {
      "Statements": [
        {
          "GeoMatchStatement": {
            "CountryCodes": [
              "CA"
            ]
          }
        },
        {
          "IPSetReferenceStatement": {
            "ARN": "arn:aws:wafv2:us-east-1:111111111111:regional/ipset/test-ip-set-22222222/33333333-4444-5555-6666-777777777777"
          }
        }
      ]
    }
  }
}
```

使用主控台規則視覺化編輯器，您可以在邏輯規則陳述式下巢狀化最可巢狀的陳述式，但無法使用視覺化編輯器來巢狀化 OR或 AND陳述式。若要設定此類型的巢狀，您需要以 JSON 提供規則陳述式。例如，下列 JSON 規則清單包含 OR陳述式的巢狀AND陳述式。

```
{
  "Name": "match_rule",
  "Priority": 0,
  "Statement": {
    "AndStatement": {
      "Statements": [
        {
          "LabelMatchStatement": {
            "Scope": "LABEL",
            "Key": "awswaf:managed:aws:bot-control:bot:category:monitoring"
          }
        },
        {
          "NotStatement": {
            "Statement": {
              "LabelMatchStatement": {
                "Scope": "LABEL",
                "Key": "awswaf:managed:aws:bot-control:bot:name:pingdom"
              }
            }
          }
        },
        {
          "OrStatement": {
            "Statements": [
              {
                "GeoMatchStatement": {
                  "CountryCodes": [
                    "JM",
                    "JP"
                  ]
                }
              },
              {
                "ByteMatchStatement": {
                  "SearchString": "JCountryString",
                  "FieldToMatch": {
                    "Body": {}
                  },
                  "TextTransformations": [
                    {
                      "Priority": 0,
                      "Type": "NONE"
                    }
                  ],
                  "PositionalConstraint": "CONTAINS"
                }
              }
            ]
          }
        }
      ]
    }
  },
  "Action": {
    "Block": {}
  },
  "VisibilityConfig": {
    "SampledRequestsEnabled": true,
    "CloudWatchMetricsEnabled": true,
    "MetricName": "match_rule"
  }
}
```