Skip to content

Instantly share code, notes, and snippets.

@pantafive
Created December 13, 2021 18:35
Show Gist options
  • Save pantafive/8ff16c70aa9b310229cc8c1f6bf0c13e to your computer and use it in GitHub Desktop.
Save pantafive/8ff16c70aa9b310229cc8c1f6bf0c13e to your computer and use it in GitHub Desktop.
nginx: docker: serve config.json generated from environment variables
version: '2.4'
services:
nginx:
build:
context: .
target: nginx
environment:
BACKEND_URL: http:/some-url.com
...
FROM alpine:3.6 as nginx
RUN apk add --no-cache nginx-mod-http-lua
RUN rm -r /etc/nginx/conf.d && rm /etc/nginx/nginx.conf
# Create folder for PID file
RUN mkdir -p /run/nginx
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY --from=builder /app/build/ /usr/share/nginx/html
CMD ["nginx"]
load_module /usr/lib/nginx/modules/ndk_http_module.so;
load_module /usr/lib/nginx/modules/ngx_http_lua_module.so;
pcre_jit on;
events {
worker_connections 1024;
}
daemon off;
# important
env BACKEND_URL;
http {
server {
listen 80;
set_by_lua $api 'return os.getenv("BACKEND_URL")';
location / {
root /usr/share/nginx/html;
index index.html;
try_files $uri $uri/ /index.html;
}
location /config.json {
default_type application/json;
return 200 '{"backend-url":"${api}"}';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment