Created
December 13, 2021 18:35
-
-
Save pantafive/8ff16c70aa9b310229cc8c1f6bf0c13e to your computer and use it in GitHub Desktop.
nginx: docker: serve config.json generated from environment variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '2.4' | |
services: | |
nginx: | |
build: | |
context: . | |
target: nginx | |
environment: | |
BACKEND_URL: http:/some-url.com | |
... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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