Configuring gateway access log files in OpenResty Edge
Today I’d show you how to configure the access log format for the application in OpenResty Edge.
Configure access log format on the global config page
As always, let’s go to the OpenResty Edge’s Admin web console. This is our sample deployment of the console. Every user has their local deployment.
Let’s start by configuring the format of the access log.
Go to the Global Config page.
The current configuration belongs to the network partition named “default”.
Let’s jump directly to the section about the log settings.
Here is the default log file directory. If you want to modify it, you must ensure that the modified directory already exists on all gateway servers.
Here is the default access log format named “main”.
This format records a lot of information, such as remote address IP, request body, upstream status, etc.
The “As default” means to set it to the default access log format of this network partition. And in the application, if we don’t change to another log format, the default is to use this.
If you want to add a new format, you can click this button.
In this tutorial we use this existing format “tutorial-example”.
It records the request time, remote IP address, HTTP host, and request body.
Configure access logs for the sample application
Now let’s configure this access log format for the application
Go to the applications page.
We still use our continuing sample application for the test-edge.com domain.
Enter the application.
Go to the settings page.
The network partition named “default” was previously configured for this application.
And the application uses the global config’s default access log format by default.
We cannot change the access log file when using the default log format.
Let’s change the log format. We select the “tutorial-example” access log format.
Now we can change the log file. We change it to “example.access.log”.
Save it.
As always, we need to make a new release to push out our changes.
Click on this button.
Ship it!
It is fully synchronized.
Now our changes have been pushed to all the gateway clusters and servers.
Our configuration changes do NOT require server reload, restart, or binary upgrade. So it’s very efficient and scalable.
Test access logs
We already have an upstream defined in our earlier tutorial.
This my_backend
upstream has a backend server defined already.
And we also have a page rule already defined.
This page rule sets up a reverse proxy to the upstream we just saw.
So when we access the application, there will be upstream content returned.
Now let’s see which gateway server our application belongs to.
Go to the gateway clusters page.
Our application belongs to the network partition named “default”.
And there are many gateway clusters belonging to the network partition named “default”.
Let’s select one of them to view the access log messages.
Let’s generate an access log message by accessing the application.
On the terminal, we send a request via curl.
curl -sSI -H 'Host: test-edge.com' http://52.53.251.226/
Access successful!
Then, let’s check the access log messages. We log in to the OpenResty Edge gateway server.
Check the last one access log message in the example.access.log file.
The log file directory is defined in the global config.
And the log file is defined in our application.
Run the command.
We can see the access log message contains the request cost time.
And remote IP address.
HTTP host.
And request body.
We can see that the access log message matches the access log format “tutorial-example”.
By the way, in addition to configuring access log format for the application in settings page, we can also configure it when we create a new application.
Go back to the applications page.
Click the new application button to see where to set the access log format.
We can set access log format here.
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.