openreplay/scripts/dockerfiles/nginx
2022-08-18 11:43:38 +02:00
..
compression.conf chore(docker): updating base image to openresty alpine 2022-08-07 12:48:25 +02:00
default.conf chore(nginx): support for env variable 2022-08-07 12:48:33 +02:00
Dockerfile main branch pull and resolved conflicts 2022-08-18 11:43:38 +02:00
location.list chore(nginx): using header same as the target service 2022-08-17 19:58:17 +02:00
nginx.conf chore(nginx): support for env variable 2022-08-07 12:48:33 +02:00
README.md chore(nginx): support for env variable 2022-08-07 12:48:33 +02:00

Nginx read urls from env

We're using openresty because of native lua support.

  1. To access the env variable using os.getenv("MY_ENV") we need to define env MY_ENV in nginx.conf

  2. use set_by_lua_block $api_endpoint { return os.getenv("MY_ENV") } in server directive of nginx.

Ref:

  1. Nginx directives: https://openresty-reference.readthedocs.io/en/latest/Directives/#set_by_lua_block
  2. env variable definition:
  3. https://github.com/openresty/lua-nginx-module#system-environment-variable-support
  4. https://nginx.org/en/docs/ngx_core_module.html#env

Run the app

docker run -v ${PWD}/nginx.conf:/usr/local/openresty/nginx/conf/nginx.conf \
-v ${PWD}/location.list:/etc/nginx/conf.d/location.list --rm -it \
-e FRONTEND_ENDPOINT="http://10.0.0.55:8000" -e API_ENDPOINT="http://10.0.0.55:9000" \
-p 80:8080 -p 9145:9145 local/nginx