Hello!
You can use https://github.com/openresty/lua-nginx-module#ngxtimerevery to create recurring tasks in ngx_lua. Based on your use case you will most likely want to setup the timer in the init_worker phase.
You can replace your rewrite directive using rewrite_by_lua and proxy_pass to arbitrary URI using variables inside rewrite_by_lua. There is no need to "generate rewrite rules" in this case.
On Thursday, November 9, 2017 at 12:18:36 PM UTC-8, Brandon wrote:
Hello, I am new to both nginx and lua, but have some questions
and am
trying to get orientated
I have been using these two sources for my documentation so far, but I'm
still having some trouble.
https://github.com/openresty/lua-nginx-module#ngxredirect
https://openresty-reference.readthedocs.io/en/latest/Directives/#rewrite_by_lua
and
I have a use case where I want to be able to define how nginx rewrites a
URL from the content of a file stored somewhere, but I'm not sure how to
actually program this or properly work with Lua in an embedded environment.
Right now I have clients that pull down assets with a curl command like
this. Internally Nginx rewrites /prod/linux/ to /12345/ and that works.
location / {
rewrite /prod/linux/(.*) /12345/$1 permanent;
proxy_pass https://bucket.s3.amazonaws.com;
}
curl -L https://me.com:8443/prod/linux/deploy.sh > deploy.sh
I have a lot of these nginx servers that may be serving different
content to different types of clients and I want to be maintaining this
mapping of client type to asset version, the /12345/ I rewrite to, in a file.
I was thinking of the mapping being formatted like this:
gce-2017-10-10,12345
azure-2017-10-10,12345
gce-2017-10-20,54321
azure-2017-10-20,98765
I want to keep a file defining this mapping on S3 and have nginx pull it
down, read it and generate appropriate rewrite rules every hour. I see
that there is a module for helping with s3 access. How can I install
such modules in the embedded lua-nginx environment?
https://github.com/gcr/lua-s3
How can I have a job like this running internal to Nginx on a regular
schedule without being in response to some access event?
Am I being an idiot and doing this wrong entirely?
I appreciate any direction someone may have