A container entrypoint renders `nginx.conf.template` with `envsubst`, and nginx fails with `nginx: [emerg] invalid number of arguments in "proxy_set_header" directive in /etc/nginx/conf.d/default.conf:12`.
IntermediateTroubleshootingTroubleshooting: tools, portability, permissions and environment
Answer
Likely causes → envsubst replaces every $VAR it sees, including nginx's own variables like $host and $remote_addr, which are unset in the shell environment and become empty. proxy_set_header Host $host; turns into proxy_set_header Host ;.
Diagnose →
sed -n '12p' /etc/nginx/conf.d/default.conf # proxy_set_header Host ;
nginx -t
Fix → Give envsubst an explicit list of variables to substitute:
envsubst '${BACKEND_HOST} ${BACKEND_PORT}' < nginx.conf.template > /etc/nginx/conf.d/default.conf
nginx -t && exec nginx -g 'daemon off;'
The official nginx image does this for /etc/nginx/templates/*.template, substituting only variables that are defined in the environment.
Prevent → Always pass the variable list to envsubst, and run nginx -t (or the equivalent config check) before starting or reloading.
More on Troubleshooting: tools, portability, permissions and environment
On a Mac, `sed -i 's/replicas: 2/replicas: 3/' deploy.yaml` fails with `sed: 1: "deploy.yaml": extra characters at the end of d command`.BeginnerA cleanup script fails on a developer's Mac with `date: illegal option -- d`.BeginnerA script that works on Ubuntu fails in an Alpine-based CI image with `grep: unrecognized option: P`.IntermediateAn `awk` one-liner works on your RHEL box but fails on Ubuntu with `awk: line 1: function gensub never defined`.Intermediate`comm -23 expected.txt installed.txt` prints `comm: file 1 is not in sorted order`, even though both files were produced with `sort`.Intermediate`grep ERROR /var/log/app/app.log` prints only `grep: /var/log/app/app.log: binary file matches`.Beginner