In this tutorial, we will demonstrate how toOpenResty EdgeConfigure a custom error page in the web console of.
Custom Template Creation
Today, I'll show you how toOpenResty EdgeCreate error pages using custom templates in.Let's enter the console first.This is an example deployment of our console.Each user will have their own deployment.
First, we click "Global Config".
Then, we enter the "Global Page Templates" page.Here, we can create some global page templates, which can customize error pages or WAF block pages.
Now, we can click this button to add a simple template.
Name the template here aserror-page-template-demo。
For HTML content, you can use some predefined variables to customize it:
For example, "CLIENT_IP",
“CLIENT_COUNTRY”,
And "HOST".
Now we can output the client IP address.
You can also output the request ID and user agent as examples.
Then we click Save.
Since this is a global configuration, changes to the page template will be published and synchronized to all gateway servers immediately.
Application of template
Next, go to our example application:
Then search test-edge.com and apply the page template as a customized error page.
Enter the application.
Then enter the "Page Rules" page.
Click "New Rules".
Let's add a new action.
You can select or search action types here.
Search for "customize error page".
Here, you can select the HTTP response status code corresponding to the error page.
Here we only select "404".
There are several ways to set a custom error page, such as using the original HTML, the Backend URL, or the previously uploaded global static file.
Now, choose to use the global page template we just defined and named "error page template demo".
Next, we need to add another action.
Click the search box.
Search for "intercept upstream errors".
Since we have configured the proxy to the upstream, enabling this operation can intercept upstream errors.
In addition, we need to put this rule before other rules, so that we can return to our customized error page.
Save it.
Usually, we need to publish a new version of the "new page rule".
Click here to publish the pending changes.
Click Publish!
It is now fully synchronized.
The new page rules have been pushed to all gateway clusters and servers.
Our configuration changes do not require a reload, restart, or binary upgrade of the server, so they are very efficient and easy to scale.
Let's verify this rule by testing a gateway server.
Copy the IP address of this San Francisco gateway server.
Then test on the terminal.
This is the IP address of the San Francisco gateway server we saw earlier.
This is a randomly generated URL that does not exist, so it can be seen that this is indeed a 404 response.
Continue to run the command.
We can output the request information in HTML format, which is very helpful for troubleshooting the causes of error pages.
If you want to output more information or change the style of the error page, you just need to edit the page template.The changes will be released and take effect immediately.
Global override rules for error pages
If you want to use the same error page for all applications, you can also configure a global override rule.
Go to the "Global Rewrite Rules" page.
Click here to add a new rule, which is almost identical to the "Page Rules" in the application.We will introduce this function through another tutorial.
Zhang Yichun is open sourceOpenResty®Project founder andOpenResty Inc.CEO and founder of the company.
Zhang Yichun (Github ID: agentzh) was born in Jiangsu, China, and now lives in the U.S. Bay Area.He was an advocate and leader of China's early open source technology and culture, and once worked for many internationally renowned high-tech enterprises, such asCloudflareYahoo, Alibaba, the pioneer of "edge computing", "dynamic tracking" and "machine programming", has more than 22 years of programming and 16 years of open source experience. As the leader of open source projects with more than 40 million global domain name users, heOpenResty®High tech enterprises created by open source projectsOpenResty Inc.It is located in the center of Silicon Valley in the United States.Its two main productsOpenResty XRay(UtilizeDynamic trackingTechnology) andOpenResty Edge(The all-purpose gateway software most suitable for microservices and distributed traffic), widely favored by many listed and large enterprises worldwide.Besides OpenResty, Zhang Yichun has contributed more than one million lines of code to many open source projects, including Linux kernel, NginxLuaJIT、GDB、SystemTap、LLVM, Perl, etc., and has written more than 60 open source software libraries.
Follow us
If you like this article, please follow usOpenResty Inc.CorporateBlog Site。You are also welcome to scan our WeChat official account:
translate
We provideEnglish versionOriginal text and Chinese translation (this article).We also welcome readers to provide translations in other languages. As long as the full text translation is not omitted, we will consider using it. Thank you very much!
Related articles
OpenResty XRayDec 21, 2023
OpenResty XRayUpdated on Apr 10, 2024Estimated reading time: 5 minutes
How to use grayscale gateway server in OpenResty Edge
What is a grayscale server
Set gateway server as grayscale server
Publish changes to grayscale server
Test changes on grayscale servers
What is a grayscale server
Set gateway server as grayscale server
Publish changes to grayscale server
Test changes on grayscale servers
OpenResty XRayDec 4, 2023
OpenResty XRayUpdated on Apr 10, 2024Estimated reading time: 3 minutes
Configure Webhooks in OpenResty Edge
Create a webhook in OpenResty Edge Admin
Trigger this webhook
View the execution history of webhook
Create a webhook in OpenResty Edge Admin
Trigger this webhook
View the execution history of webhook
OpenResty XRayNov 21, 2023
OpenResty XRayUpdated on Apr 10, 2024Estimated reading time: 4 minutes
Configure DNS records in OpenResty Edge
Add DNS record
Test DNS records
Configure authoritative DNS server
Add DNS record
Test DNS records
Configure authoritative DNS server
OpenResty XRayNov 15, 2023
OpenResty XRayUpdated on Apr 10, 2024Estimated reading time: 4 minutes
How to add a custom response header (using OpenResty Edge)
Add a new response header with a string as a value
Built in variable with "System Hostname" as the value
Add a new response header with a string as a value
Built in variable with "System Hostname" as the value
OpenResty XRayNov 13, 2023
OpenResty XRayUpdated on Apr 10, 2024Estimated reading time: 4 minutes
User management and access control of web console (OpenResty Edge)
Create a new normal user account
Basic configuration and role-based access control
Configure Access Control
Test configuration effect
Create a new normal user account
Basic configuration and role-based access control
Configure Access Control
Test configuration effect
Article Contents
Popular articles
OpenResty XRayMay 2, 2016
OpenResty XRayMay 2, 2016
Random talk on dynamic tracking technology
What is dynamic tracking
Advantages of dynamic tracking
DTrace and SystemTap
Application of SystemTap in production
Flame diagram
Methodology
Knowledge is power
Open source and debugging symbols
Linux kernel support
Hardware Tracking
Analysis of the remains of the death process
Traditional debugging technology
A messy debugging world
OpenResty XRay
OpenResty XRaySep 7, 2020
OpenResty XRaySep 7, 2020
Introduction to Lua level CPU flame diagram
What is a flame diagram
Simple Lua sample
Complex Lua applications
Sampling overhead
Security
compatibility
Other types of Lua level flame diagram
OpenResty XRayAug 10, 2020
OpenResty XRayAug 10, 2020
Memory fragmentation in OpenResty and Nginx shared memory areas
Empty shared memory area
Fill similar sized entries
Remove Odd Keys
Delete the key in the first half
Mitigate memory fragmentation
OpenResty XRayAug 4, 2020
OpenResty XRayAug 4, 2020
How does OpenResty and Nginx's shared memory consume physical memory
Slab and memory page
Allocated memory may not be consumed
Spurious memory leak
HUP Reload
OpenResty XRayJan 21, 2020
OpenResty XRayJan 21, 2020
How OpenResty and Nginx allocate and manage memory
System level
Application level
Traditional Nginx server
OPENRESTYApr 25, 2019
OPENRESTYApr 25, 2019
Long term recruitment of outstanding talents
Back end engineer/system engineer
Sales Engineer
Latest articles
OpenResty XRayMay 12, 2024
OpenResty XRayMay 12, 2024
Introduction to OpenResty XRay Mobile Applications
Download and install OpenResty XRay for Android
Log in to OpenResty XRay
Fully automated analysis report
View performance chart data on the dashboard page
Guided analysis function
OpenResty XRayMay 11, 2024
OpenResty XRayMay 11, 2024
Online locating large memory objects in the PHP process (using OpenResty XRay)
Problem: Memory usage is too high
Locating large memory objects or values in the PHP process
Fully automated analysis and reporting
OpenResety EdgeMay 8, 2024
OpenResety EdgeMay 8, 2024
Enable automatic health check of gateway server in OpenResty Edge
Create a new page rule
Enable health check
test result
About OpenResty Edge
OpenResety EdgeApr 28, 2024
OpenResety EdgeApr 28, 2024
How to use gateway partition in OpenResty Edge
Create a new partition
Create a new application in the new partition
Create a new page rule
Test the new partition
About OpenResty Edge
OpenResety EdgeApr 10, 2024
OpenResety EdgeApr 10, 2024
Precisely restore the real client IP address in OpenResty Edge
Set the "Real Source IP Trust Address" and "Real IP Source" in the global configuration
Configure the app to output the client address
Verify the client address received in OpenResty Edge
About OpenResty Edge
Related articles
OpenResety EdgeDec 21, 2023
OpenResety EdgeDec 21, 2023
How to use grayscale gateway server in OpenResty Edge
What is a grayscale server
Set gateway server as grayscale server
Publish changes to grayscale server
Test changes on grayscale servers
OpenResety EdgeDec 4, 2023
OpenResety EdgeDec 4, 2023
Configure Webhooks in OpenResty Edge
Create a webhook in OpenResty Edge Admin
Trigger this webhook
View the execution history of webhook
OpenResety EdgeNov 21, 2023
OpenResety EdgeNov 21, 2023
Configure DNS records in OpenResty Edge
Add DNS record
Test DNS records
Configure authoritative DNS server
OpenResety EdgeNov 15, 2023
OpenResety EdgeNov 15, 2023
How to add a custom response header (using OpenResty Edge)
Add a new response header with a string as a value
Built in variable with "System Hostname" as the value
OpenResety EdgeNov 13, 2023
OpenResety EdgeNov 13, 2023
User management and access control of web console (OpenResty Edge)