OpenResty Edge Static Files: Serve Assets from the Gateway with No Back-to-Source
With OpenResty Edge you can store static files directly on the gateway’s Global Static File storage and use a page rule to return them straight from the edge, without back-to-source to an origin — which is higher performance and more reliable. You can match a single file by its exact URI, serve a whole directory by URI prefix, and optionally strip a prefix from the request with Ignore URI Prefix. This tutorial walks through uploading the files and wiring up each matching mode.
Upload Static Files to OpenResty Edge
Let’s go to the OpenResty Edge’s Admin web console. This is our sample deployment of the console. Every user has their own local deployment.
We start by uploading the static files to OpenResty Edge.
Go to the Global Static File page.
Create a directory.
We name it “test”.
Create.
Here is the directory we create.
Enter the directory.
Then we upload the file.
Select the file “bird.jpg”.
Save the file.
Create a subdirectory.
We name it “images”.
Create.
Enter the directory.
Then we upload another file.
Select the file “cat.jpg”.
Save the file.
Serve a Static File with a Page Rule
The files have been uploaded, so let’s use them next.
We can still use our continuing sample application, test-edge.com.
Enter the application.
Go to the Page Rules page.
Here’s a page rule created in an earlier video tutorial.
Let’s create a new page rule to return a file directly.
We enable a rule condition to check for the URI /images/bird.jpg.
We choose the string equality operator.
Enter the value /images/bird.jpg to match the static file.
And turn on the Content.
Select a file that we just uploaded.
Expand the directory.
Select image “bird.jpg”.
We insert this page rule before the proxy page rule.
Create the rule.
We need to make a new release to push out our new changes, as always.
Click on this button.
Ship it!
Our new release is now synchronized to all our gateway servers.
Test the Static File Page Rules
Then we send an HTTP request with URI “images/bird.jpg”.
A bird image was returned, which is what we expected precisely.
Serve a Whole Directory by Prefix
After demonstrating the return file, next, we illustrate the directory.
Go to the Page Rules page.
Edit the Page Rule.
Choose the operator “Prefix matches”.
Enter the value /images to match the static resource location only.
Select the directory that we just created.
“Ignore URI Prefix” allows the requested URL to be different from the actual resource URI, which we will demonstrate later.
Save the rule.
We need to make a new release to push out our new changes, as always.
Click on this button.
Ship it!
Our new release is now synchronized to all our gateway servers.
Then we send a request with URI “images/cat.jpg”.
The request returned a cat image in the subdirectory “images”.
What will happen if we request “images/bird.jpg”?
The request returned the error page. There is no “bird.jpg” file in the “images” subdirectory.
Ignore the URI Prefix
Next, we demonstrate how to ignore the URI prefix.
Go to the Page Rules page.
Edit the Page Rule.
We still use the “test” directory.
Then choose to ignore “String”.
Type “/images/”.
Save the rule.
We need to make a new release to push out our new changes, as always.
Click on this button.
Ship it!
Our new release is now synchronized to all our gateway servers.
we send a request with the “/images” prefix.
The request returned a bird image.
Then we request the image in the subdirectory “images”.
The request returned a cat image.
Then we send a request with the “/no” prefix of a non-existent resource.
The error page was returned.
This stores and serves static files directly at the gateway. If instead you want to cache dynamic responses fetched from an origin, see caching rules in OpenResty Edge; to serve assets globally as your own private CDN, see building a private CDN with OpenResty Edge.
FAQ
Can OpenResty Edge serve static files without going back to the origin?
Yes. Once a file is uploaded to the Global Static File storage, a page rule returns it directly from the gateway, so the request does not need to back-to-source. This is higher performance and more reliable.
How do I serve a single file versus a whole directory?
Use a page rule with the string-equality operator to match one exact URI (for example /images/bird.jpg), or use the “Prefix matches” operator to serve an entire uploaded directory under a URI prefix (for example /images).
What does “Ignore URI Prefix” do?
It allows the requested URL to differ from the actual resource URI by stripping a prefix (for example /images/) from the request before the file is looked up.
How do I push a new static file or page rule live?
Make a new release. The release is then synchronized to all your gateway servers.
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.

























































































