Currently I have a nginx server running in a container and want to display a static page when someone access https://example.com/showname/. The static page need to show the pod name get from the environment variable, is there a way to do this?
my env var name:deployment_env and below is static page code
<html>
<head>
<title>Test NGINX passed</title>
</head>
<body>
<h1>deploy_env</h1>
<h1><span id="deploy_env" style="display: block;"></span></h1>
<script>
var env = window.env;
var deploy = document.querySelector('#deploy_env');
deploy.textContent = env.deployment_env;
</script>
</body>
</html>
If you are using the official nginx docker image, there is an easy way since the image contains envsubst functionality for quite some time now.
showname.html
env.js.template
Dockerfile
docker-compose.yml
showname.html.template
Dockerfile
I admit that this functionality in the image was supposed to be used for configuration files only. If you want a cleaner solution, you might want to adjust the docker entrypoint to add a different envsubst usage.