To configure a custom error page in OpenResty Edge, create a reusable global page template under Global Config, then apply it in an application’s Page Rules by HTTP response status code (for example, 404) and enable intercept upstream errors. Templates support predefined variables such as CLIENT_IP, CLIENT_COUNTRY, and HOST, and every change is released and synced to all gateway servers immediately — with no reload, restart, or binary upgrade.

This tutorial walks through the full setup on the OpenResty Edge web console: creating the template, applying it as a customized error (or WAF blocking) page, testing it on a live gateway, and reusing one error page across every application with a global rewrite rule.

Create a Custom Error Page Template

Let’s go to the console first. This is our sample deployment of the console. Every user would have their own deployment.

OpenResty Edge web console sample deployment

First, we go to Global Config Tab.

OpenResty Edge Global Config tab

Then we go to the Global Page Templates page. Here we can create some global page templates, which can be used to define customized error pages or WAF blocking pages.

Global Page Templates page in OpenResty Edge

Now we can add a simple template by clicking this button.

Add a new global page template button

Here we can name this template as ’error-page-template-demo'.

Naming the error page template error-page-template-demo

For the HTML content, you can customize it with some predefined variables:

Editing custom HTML content with predefined variables

like ‘CLIENT_IP’,

Predefined CLIENT_IP variable in the page template

‘CLIENT_COUNTRY’,

Predefined CLIENT_COUNTRY variable in the page template

and ‘HOST’.

Predefined HOST variable in the page template

We can now output the client IP.

Outputting the client IP in the error page template

Also request ID, and user agent header as an example.

Adding request ID and user-agent header to the error page

Then we save it.

Saving the custom error page template

Changes to this page template will be released and synced to all gateway server immediately since this is a global configuration.

Page template changes released and synced to all gateway servers

Apply the Template as a Custom Error Page

Next, go to our example application:

Opening the example application in OpenResty Edge

Then go to test-edge.com to apply the page template as a customized error page.

Selecting test-edge.com to apply the custom error page

Enter the application.

Entering the test-edge.com application

Then go to the Page Rules page.

Opening the Page Rules page

Starting by adding a new rule.

Adding a new page rule

We add a new action.

Adding a new action to the page rule

You can select or search action types here.

Selecting an action type from the search box

Search for “customize error page”.

Searching for the customize error page action

Here you choose the HTTP response status codes for the erorr page.

Choosing HTTP response status codes for the error page

We choose only ‘404’ here.

Selecting the 404 status code

There are several ways to set the customized error page, like raw HTML or using backend URL, or global static file we already uploaded previously.

Custom error page source options: raw HTML, backend URL, or global static file

And now, choose to use the global page template we just defined and named as ’error-page-template-demo’.

Choosing the global page template error-page-template-demo

Then we need to add one more action.

Adding one more action to the page rule

Click the search box.

Clicking the action search box

Search for “intercept upstream errors”.

Searching for the intercept upstream errors action

Enable this action to intercept upstream errors since we’ve configured the proxy to upstream.

Enabling intercept upstream errors for the upstream proxy

Also, we need to put this rule before any other rules so that we can return our customized error page.

Ordering the rule before all other rules

OK to save it.

Saving the page rule

As usual, we need to make a new release to push out our new page rule.

Making a new release to push the page rule

Click here to release the pending change.

Releasing the pending change

Ship it!

Confirming the release

It is fully synchronized now.

Configuration fully synchronized across clusters

Now the new page rule has been pushed to all the gateway clusters and servers.

Page rule pushed to all gateway clusters and servers

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

Configuration changes require no server reload, restart, or binary upgrade

Test the Custom Error Page on a Gateway

Let’s test a gateway server for this rule.

Selecting a gateway server to test the rule

We copy the IP address of this San Francisco gateway server.

Copying the IP address of the San Francisco gateway server

Then we test on the terminal.

Testing the gateway server from the terminal

This is the IP address of the San Francisco gateway server we saw earlier.

IP address of the San Francisco gateway server

And this is a randomly generated URL that does not exist, so it is indeed a 404 response.

Requesting a random nonexistent URL that returns 404

Run the command.

Running the curl command against the gateway

We can get the request info output in html which can be helpful when something is wrong.

Custom 404 error page output with request info in HTML

If you want to output more info or change the style of the error page, you can just edit the page template. The changes will be released and take effect immediately.

Custom 404 error page output, updated by editing the page template

Reuse One Error Page Across All Applications

If you want to use the same error page for all applications, you can also config a global rewrite rule.

Using a global rewrite rule for the same error page across applications

Go to “Global Rewrite Rules” page.

Opening the Global Rewrite Rules page

Add a new rule by clicking here, and it’s almost the same as the “Page Rule” in an application. We’ll have another tutorial to introduce this.

Adding a new global rewrite rule

Frequently Asked Questions

How do I set a custom 404 page in OpenResty Edge?

Create a global page template under Global Config, then add a Page Rule in your application with the “customize error page” action, select the 404 status code, and point it at your template. Also enable “intercept upstream errors” if you proxy to an upstream, and order the rule before all others so the custom page is returned.

Can I use one custom error page for all applications?

Yes. Instead of adding a Page Rule per application, go to the Global Rewrite Rules page and add a rule there. It works almost the same as an application’s Page Rule, but applies the same custom error page across all applications on the gateway.

What variables can I use in an OpenResty Edge error page template?

The HTML content of a page template supports predefined variables such as CLIENT_IP, CLIENT_COUNTRY, and HOST. You can also output values like the request ID and the User-Agent header, which is helpful for debugging when something goes wrong.

Do custom error page changes require a gateway reload or restart?

No. Because page templates are a global configuration, changes are released and synced to all gateway servers immediately. Editing the template takes effect right away, with no server reload, restart, or binary upgrade — so it stays efficient and scalable across large clusters.

Can I customize the WAF blocking page too?

Yes. Global page templates can define both customized error pages and WAF blocking pages, so the same reusable template mechanism covers both cases.

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.