01_nginx_config_template.sh 938 B

12345678910111213141516171819202122232425262728293031323334
  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_WORKER_PROCESSES="${NGINX_WORKER_PROCESSES:-4}"
  15. export NGINX_WORKER_CONNECTIONS="${NGINX_WORKER_CONNECTIONS:-768}"
  16. echo "Nginx: generating config file from template"
  17. # Note the single-quotes, they are important.
  18. # This is a pass-list of env-vars that envsubst
  19. # should operate on.
  20. envsubst '${NGINX_WORKER_PROCESSES} ${NGINX_WORKER_CONNECTIONS}' \
  21. < "${nginx_template_file}" \
  22. > "${nginx_config_file}"
  23. echo "Nginx: reloading config"
  24. service nginx reload
  25. fi