OpenResty Edge ships with a built-in, high-performance WAF that you enable per application from the web console: pick the rule sets, trial them in log-only mode, check the hit logs, then switch the action to blocking with a 403 response — all published to every gateway server without any reload or restart.

OpenResty Edge’s WAF engine is also several times faster than open-source WAFs like ModSecurity and lua-resty-waf; see the WAF benchmark against ModSecurity for the numbers. This tutorial focuses on the console operations: enabling, testing, tuning, and extending the WAF step by step.

Enable the WAF for an Application in Log-Only Mode

Let’s go to the web console of OpenResty Edge. This is our sample deployment of the console. Every user has their own deployment.

OpenResty Edge web console home page with the list of applications

We use our continuing sample application for the test-edge.com domain.

Searching for the test-edge.com domain in the applications list

Let’s enter this application.

The sample application for the test-edge.com domain in the filtered list

Go to the Page Rules page.

The Page Rules menu of the application

We already have a reverse proxy page rule set up in an earlier tutorial.

An existing reverse proxy page rule in the application

Now let’s enable some WAF rulesets.

Edit the page rules.

The Edit button of the page rule

Click the WAF switch to enable it.

The WAF switch in the Edit Rule dialog to be turned on

The WAF options expanded after enabling the WAF switch

Here we can choose the WAF rulesets to enable.

The WAF Rules field in the page rule for choosing rule sets

Here we just keep the default rulesets.

Keeping the default WAF rule sets selected

Select the action for the requests hitting the WAF rules.

Selecting the action for requests hitting the WAF rules

The Log only action helps test the WAF rule itself without worrying about affecting the requests.

Choosing the Log Only action to test WAF rules safely

Save the rule.

Saving the page rule with WAF enabled

We need to make a new configuration release to push out our new changes, as always.

The pending change notice for releasing the new WAF configuration

Click on this button.

Clicking the release button for the configuration changes

Ship it!

Confirming the release of the WAF configuration

Our new release is now synchronized to all our gateway servers.

The release synchronized to all gateway servers

Now the change has been pushed to all the gateway clusters and servers.

Animation: configuration syncing to all gateway clusters (start)

Animation: configuration syncing to all gateway clusters (in progress)

Animation: configuration syncing to all gateway clusters (complete)

Our configuration changes do NOT require server reload, restart, or binary upgrade. So it’s very efficient and scalable.

Diagram: the Edge Admin syncs configuration into each gateway node’s local storage and updates running processes without any reload

Send a Test Attack and Review the WAF Logs

Let’s send a malicious request attempting a SQL injection.

The origin site’s default index page returned for the SQL injection test in Log Only mode

The request returned the default index page of the origin site. It was to be expected since we chose to log hits only.

Let’s check the WAF hit Logs in the web console.

The WAF Logs menu item in the OpenResty Edge console

The WAF logs page listing recorded rule hits

We can see that the rule was indeed hit and logged.

A WAF log entry showing the SQL injection rule hit in Log Only mode

This part shows the details of the individual requests caught by the WAF.

Details of the individual request caught by the WAF

Click the Check Rule button to see the details of the WAF rule matched.

The Check Rule button for viewing the matched WAF rule

Show the rule definition in the Edge language.

The matched WAF rule definition shown in EdgeLang

Disable and Re-enable Individual WAF Rules

If you find any false positives, you can toggle this switch to disable the corresponding WAF rule individually.

The per-rule switch in the WAF log entry for disabling the rule

Disabled rules will be displayed on the WAF Config page.

The WAF Config menu item in the sidebar

Here is the list of disabled WAF rules.

The list of disabled WAF rules

And this is the WAF rule we just disabled.

The WAF rule just disabled in the list

Click the Delete button to re-enable the rule.

The Delete button that re-enables a disabled WAF rule

The confirmation dialog for deleting the disabled entry to re-enable the rule

Add a WAF Whitelist to Save CPU Cycles

Furthermore, you can add a WAF white-list to skip requests which should bypass the WAF to save CPU cycles.

The WAF Whitelist section on the WAF Config page

For example, static assets generally don’t need WAF filtering. Skipping those resources can reduce the overhead on your servers.

The New WAF Whitelist Rule button

The New WAF Whitelist Rule form with a URI prefix-match condition

Return 403 on a WAF Hit: Sensitivity and Risk-Score Thresholds

This time, let’s change the “Log only” action to something else. Like returning a 403 error response.

Diagram: the OpenResty Edge WAF returns a 403 Forbidden response to a blocked request

Go to the Page Rules page.

The Page Rules menu item in the sidebar

Edit the page rule again.

Editing the page rule again to change the WAF action

Change the action.

Changing the WAF action in the page rule

We’ll block malicious requests this time.

Selecting the blocking action for malicious requests

Here we can set the sensitivity level.

Setting the WAF sensitivity level in the page rule

Alternatively, we can also set a score number directly.

Setting the minimum risk score threshold directly

It is the sum of the risk scores of all the matched WAF rules. The action will not run until the total score threshold is reached.

Save the rule.

Saving the page rule

Release the configuration changes again.

The pending change notice after switching to the 403 block action

Clicking the release button

Confirming the release

The updated configuration synced to all gateway servers

Verify the 403 Block in the WAF Logs

Send the malicious request again.

The 403 Forbidden block page returned for the resent SQL injection request

The server returned a “403 Forbidden” response this time.

Check out the WAF Logs page again.

The WAF Logs menu item after releasing the blocking configuration

The action logged is indeed “Block with HTTP code 403” here.

A WAF log entry showing Block with HTTP code 403 as the action

Create Your Own WAF Rule Set in EdgeLang

The WAF platform is very flexible and extensible. You can also create your own WAF rulesets.

Go to the Global Config page.

The Global Config tab in the top navigation

Click the “Global WAF” menu item.

The Global WAF menu item

Click the New Rule Set button.

The New Rule Set button on the Global WAF page

Enter the ruleset name here, and definition here.

Entering the WAF rule set name and definition

And also custom WAF rules in our Edge language, or Edgelang for short.

The EdgeLang code editor in the New Rule Set dialog

And then we can save it.

Saving the new WAF rule set

Quit this page.

However many rule sets you enable, the WAF stays fast: OpenResty Edge combines all the rules’ regular expressions into a single state machine and scans each request only once. See how the OpenResty Edge WAF outperforms ModSecurity for the implementation details and benchmark numbers.

FAQ: WAF on OpenResty

Does open-source OpenResty have a built-in WAF?

No. Open-source OpenResty ships no WAF module. The WAF in this tutorial is a feature of OpenResty Edge, the commercial gateway product built on OpenResty, which includes the managed rule sets, log-only mode, WAF logs, and blocking actions shown above out of the box.

Can I run ModSecurity on open-source OpenResty?

There is no official ModSecurity module for OpenResty. You would have to compile libmodsecurity and the third-party nginx connector against OpenResty’s bundled nginx yourself, and ModSecurity’s original vendor ended its support in 2024, handing the project over to community maintenance. It is a fully self-supported path today.

Is lua-resty-waf still an option for OpenResty?

Not really. lua-resty-waf has been unmaintained for years and is not recommended for new production deployments. For a maintained WAF on the OpenResty stack, the practical option is the built-in WAF in OpenResty Edge, which is the engine this tutorial configures.

How do I test WAF rules without blocking real traffic?

Set the WAF action to “Log only” when enabling the rule sets. Requests that match rules pass through to the origin unchanged, but every hit is recorded in the WAF logs, where the Check Rule button shows exactly which rule matched. Once the rules look right, switch the action to blocking and release the configuration.

How does the OpenResty Edge WAF decide when to block a request?

Every matched WAF rule carries a risk score, and the scores of all matched rules are summed per request. The block action fires only when the total reaches the threshold, which you set either by choosing a sensitivity level or by entering a score number directly.

How do I disable a single WAF rule in OpenResty Edge?

If a rule keeps matching legitimate traffic, toggle off just that rule from the WAF logs; the rest of the rule set keeps running. Disabled rules are listed on the WAF Config page, where deleting the entry re-enables the rule. You can also whitelist requests that don’t need filtering at all, such as static assets, which saves CPU cycles too.

What is OpenResty Edge

OpenResty Edge is our all-in-one gateway software for microservices and distributed traffic architectures. It combines traffic management, private CDN construction, API gateway, security, and more to help you easily build, manage, and protect modern applications. OpenResty Edge delivers industry-leading performance and scalability to meet the demanding needs of high concurrency, high load scenarios. It supports scheduling containerized application traffic such as K8s and manages massive domains, making it easy to meet the needs of large websites and complex applications.

If you like this tutorial, please subscribe to this blog site and/or our YouTube channel. Thank you!

About The Author

Yichun Zhang (Github handle: agentzh), is the original creator of the OpenResty® open-source project and the CEO of OpenResty Inc..

Yichun is one of the earliest advocates and leaders of “open-source technology”. He worked at many internationally renowned tech companies, such as Cloudflare, Yahoo!. He is a pioneer of “edge computing”, “dynamic tracing” and “machine coding”, with over 22 years of programming and 16 years of open source experience. Yichun is well-known in the open-source space as the project leader of OpenResty®, adopted by more than 40 million global website domains.

OpenResty Inc., the enterprise software start-up founded by Yichun in 2017, has customers from some of the biggest companies in the world. Its flagship product, OpenResty XRay, is a non-invasive profiling and troubleshooting tool that significantly enhances and utilizes dynamic tracing technology. And its OpenResty Edge product is a powerful distributed traffic management and private CDN software product.

As an avid open-source contributor, Yichun has contributed more than a million lines of code to numerous open-source projects, including Linux kernel, Nginx, LuaJIT, GDB, SystemTap, LLVM, Perl, etc. He has also authored more than 60 open-source software libraries.