200_nginx_config_template.sh 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #!/bin/sh
  2. set -e
  3. ## Generate nginx config files from templates,
  4. ## with environment variables substituted
  5. nginx_dir='/etc/nginx'
  6. nginx_templates_dir="${nginx_dir}/templates"
  7. if ! [ -d "${nginx_templates_dir}" ]; then
  8. echo "Nginx: no template directory found, skipping"
  9. exit 0
  10. fi
  11. nginx_template_file="${nginx_templates_dir}/nginx.conf.template"
  12. nginx_config_file="${nginx_dir}/nginx.conf"
  13. if [ -f "${nginx_template_file}" ]; then
  14. export NGINX_KEEPALIVE_TIMEOUT="${NGINX_KEEPALIVE_TIMEOUT:-65}"
  15. export NGINX_WORKER_CONNECTIONS="${NGINX_WORKER_CONNECTIONS:-768}"
  16. export NGINX_WORKER_PROCESSES="${NGINX_WORKER_PROCESSES:-4}"
  17. echo "Nginx: generating config file from template"
  18. # Note the single-quotes, they are important.
  19. # This is a pass-list of env-vars that envsubst
  20. # should operate on.
  21. # shellcheck disable=SC2016
  22. envsubst '
  23. ${NGINX_KEEPALIVE_TIMEOUT}
  24. ${NGINX_WORKER_CONNECTIONS}
  25. ${NGINX_WORKER_PROCESSES}
  26. ' \
  27. < "${nginx_template_file}" \
  28. > "${nginx_config_file}"
  29. echo "Checking Nginx config"
  30. nginx -t
  31. echo "Nginx: reloading config"
  32. service nginx reload
  33. fi