I had a hard time finding a decent example on how to use the lua nginx module to get environment variables and pass them to the location block for the proxy settings, so wanted to share the solution that worked for me.
Example nginx conf:
env NGROK_URL;
events {
worker_connections 1024;
}
http{
access_log /var/log/access.log;
server {
listen 80;
location / {
set_by_lua $ngrok_url 'return os.getenv("NGROK_URL")';
proxy_pass http://$ngrok_url;
proxy_set_header Host $ngrok_url;
resolver 8.8.8.8;
}
}
}
If you are trying to do this using the openresty docker image, another thing you will want to do is overwrite the base
default nginx.cong in the image. Replace the nginx.conf at /usr/local/openresty/nginx/conf/nginx.conf
in the
openresty docker image.