OpenResty is nginx bundled with LuaJIT, letting you run Lua code directly in nginx configs. Testing locally avoids deploying untested changes to production.
Docker provides an isolated OpenResty environment without installing anything on your machine. Mount your config, test your Lua code, iterate quickly.
#Create a minimal test config
Create nginx_dev.conf with only what you need to test:
worker_processes 1;
events {
worker_connections 1024;
}
http {
lua_shared_dict rps_dict 10m;
# Seed test data on startup
init_worker_by_lua_block {
local dict = ngx.shared.rps_dict
dict:set("resp:/vast/TEST1:200", 10)
dict:set("resp:/vast/TEST1:204", 150)
dict:set("resp:/ortb2/TEST2:429", 5)
}
server {
listen 80;
location = /metrics {
content_by_lua_block {
-- your Lua code here
ngx.say("hello")
}
}
}
}
#Run OpenResty in Docker
docker run -it --rm -p 8888:80 \
-v $(pwd)/nginx_dev.conf:/usr/local/openresty/nginx/conf/nginx.conf:ro \
openresty/openresty:alpine
#Test your endpoint
curl localhost:8888/metrics
#Iterate faster
Edit the config, stop the container (Ctrl+C), rerun. Or for faster iteration, run in background and reload:
# Run in background
docker run -d --name resty-dev -p 8888:80 \
-v $(pwd)/nginx_dev.conf:/usr/local/openresty/nginx/conf/nginx.conf:ro \
openresty/openresty:alpine
# Reload after config changes
docker exec resty-dev nginx -s reload
# View logs
docker logs -f resty-dev
# Cleanup
docker rm -f resty-dev
No need to rebuild anything. Edit, reload, test.