In this tutorial, we will show you how to useOpenResty EdgeAdd a custom response header in the without restarting or reloading the server process.
Add a new response header with a string as a value
Let's goOpenResty EdgeAdmin Web Console for.This is the sample deployment of our console.Each user has its own local deployment.We can continue to use the previous example application, "test edge. com".
Enter the application.
First, enter the "Page Rules" page.
Click here to add a new page rule.
Add an action.
We select Add response header.
The response header has two parts, its name and corresponding value.
Name the response header "X-TEST-EXTRA-HEADER".
For the values here, you can choose to use strings or built-in variables. Let's test with strings first.
Enter "hello world".
Ensure that this rule runs before any existing normal rules.
Save this page rule.
As usual, we need to release a new version to push our changes.
release!
The new version has now been synchronized to all gateway servers.
Now, the new page rules have been pushed to all gateway clusters and servers.
These configuration changes do not require a server reload, restart, or binary upgrade.So it is very efficient and scalable.
Let's test it on the gateway server.
We copy the IP address of the San Francisco gateway server.
Then test on the terminal.
Here is the "X-TEST-EXTRA-HEADER" response header we added.
Built in variable with "System Hostname" as the value
Next, let's try using the built-in variable as the value of the response header.
Edit this page rule.
Select the built-in variable as the value of the response header.
Currently, we provide two options for built-in variables.One is "Request Header", which means you can retrieve request information.You need to specify "Request Header" by name, such as "Origin", "Referer", etc.
The other is "System Hostname", which is the name of the gateway server we set up earlier.
Let's try "System Hostname".
Save it.
As just now, we need to publish to push this new page rule.
release!
Now it has been pushed to all gateway clusters and servers.
First, we can check the host name of the previous server.
The host name of this gateway server is as follows.
Then switch to the terminal.
The value of the "X-TEST-EXTRA-HEADER" response header has been changed to the hostname we just saw.
Let's test another gateway server, such as this one in Frankfurt, whose host name is as follows.
Switch back to the terminal again.
Now the value of the response header is the host name of the Frankfurt server.
OpenResty EdgeIt is a fully functional gateway software that we independently developed and is most suitable for microservices and distributed traffic.It provides various functions such as page rules, Web Application Firewall (WAF), load balancing, etc.
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 23, 2023
OpenResty XRayUpdated on Apr 10, 2024Estimated reading time: 4 minutes
Configure custom error pages in OpenResty Edge
Custom Template Creation
Application of template
Verification of page rules
Global override rules for error pages
Custom Template Creation
Application of template
Verification of page rules
Global override rules for error pages
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 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 23, 2023
OpenResety EdgeNov 23, 2023
Configure custom error pages in OpenResty Edge
Custom Template Creation
Application of template
Verification of page rules
Global override rules for error pages
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 13, 2023
OpenResety EdgeNov 13, 2023
User management and access control of web console (OpenResty Edge)