97 lines
3.2 KiB
Bash
Executable File
97 lines
3.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
|
|
|
case "$DOKKU_DISTRO" in
|
|
debian)
|
|
echo "%dokku ALL=(ALL) NOPASSWD:/usr/sbin/invoke-rc.d nginx reload, /usr/sbin/nginx -t" > /etc/sudoers.d/dokku-nginx
|
|
;;
|
|
|
|
ubuntu)
|
|
echo "%dokku ALL=(ALL) NOPASSWD:/etc/init.d/nginx reload, /usr/sbin/nginx -t" > /etc/sudoers.d/dokku-nginx
|
|
;;
|
|
|
|
opensuse)
|
|
echo "%dokku ALL=(ALL) NOPASSWD:/sbin/service nginx reload, /usr/sbin/nginx -t" > /etc/sudoers.d/dokku-nginx
|
|
;;
|
|
|
|
arch)
|
|
echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/systemctl reload nginx, /usr/sbin/nginx -t" > /etc/sudoers.d/dokku-nginx
|
|
;;
|
|
|
|
centos)
|
|
echo "%dokku ALL=(ALL) NOPASSWD:/usr/bin/systemctl reload nginx, /usr/sbin/nginx -t" > /etc/sudoers.d/dokku-nginx
|
|
echo "Defaults:dokku !requiretty" >> /etc/sudoers.d/dokku-nginx
|
|
;;
|
|
esac
|
|
|
|
chmod 0440 /etc/sudoers.d/dokku-nginx
|
|
|
|
# if dhparam.pem has not been created, create it the first time
|
|
if [[ ! -f /etc/nginx/dhparam.pem ]]; then
|
|
openssl dhparam -out /etc/nginx/dhparam.pem 2048
|
|
chown root:root /etc/nginx/dhparam.pem
|
|
fi
|
|
|
|
# if dokku.conf has not been created, create it
|
|
if [[ ! -f /etc/nginx/conf.d/dokku.conf ]]; then
|
|
mkdir -p /etc/nginx/conf.d
|
|
chown root:root /etc/nginx/conf.d
|
|
cat<<EOF > /etc/nginx/conf.d/dokku.conf
|
|
include $DOKKU_ROOT/*/nginx.conf;
|
|
|
|
server_tokens off;
|
|
|
|
# Settings from https://mozilla.github.io/server-side-tls/ssl-config-generator/
|
|
ssl_session_cache shared:SSL:20m;
|
|
ssl_session_timeout 1d;
|
|
ssl_session_tickets on;
|
|
|
|
ssl_dhparam /etc/nginx/dhparam.pem;
|
|
ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS;
|
|
|
|
EOF
|
|
fi
|
|
|
|
# allow users to override their server_names_hash_bucket_size
|
|
if [[ ! -f /etc/nginx/conf.d/server_names_hash_bucket_size.conf ]]; then
|
|
echo 'server_names_hash_bucket_size 512;' >| /etc/nginx/conf.d/server_names_hash_bucket_size.conf
|
|
fi
|
|
|
|
# revert dokku group changes
|
|
gpasswd -a dokku adm
|
|
chgrp -R adm /var/log/nginx
|
|
gpasswd -M "" dokku
|
|
[[ -f /etc/logrotate.d/nginx ]] && sed -i -e 's/create 0640 www-data dokku/create 0640 www-data adm/g' /etc/logrotate.d/nginx
|
|
|
|
# Create nginx error templates
|
|
mkdir -p "${DOKKU_LIB_ROOT}/data/nginx-vhosts/dokku-errors"
|
|
cp "${PLUGIN_CORE_AVAILABLE_PATH}/nginx-vhosts/templates/400-error.html" "${DOKKU_LIB_ROOT}/data/nginx-vhosts/dokku-errors/400-error.html"
|
|
cp "${PLUGIN_CORE_AVAILABLE_PATH}/nginx-vhosts/templates/404-error.html" "${DOKKU_LIB_ROOT}/data/nginx-vhosts/dokku-errors/404-error.html"
|
|
cp "${PLUGIN_CORE_AVAILABLE_PATH}/nginx-vhosts/templates/500-error.html" "${DOKKU_LIB_ROOT}/data/nginx-vhosts/dokku-errors/500-error.html"
|
|
|
|
|
|
# patch broken nginx 1.8.0 logrotate
|
|
[[ -f /etc/logrotate.d/nginx ]] && sed -i -e 's/invoke-rc.d/service/g' /etc/logrotate.d/nginx
|
|
|
|
case "$DOKKU_DISTRO" in
|
|
debian)
|
|
NGINX_INIT="/usr/sbin/invoke-rc.d"
|
|
"$NGINX_INIT" nginx start || "$NGINX_INIT" nginx reload
|
|
;;
|
|
|
|
ubuntu)
|
|
NGINX_INIT="/etc/init.d/nginx"
|
|
"$NGINX_INIT" start || "$NGINX_INIT" reload
|
|
;;
|
|
|
|
opensuse)
|
|
NGINX_INIT="/sbin/service"
|
|
"$NGINX_INIT" nginx start || "$NGINX_INIT" nginx reload
|
|
;;
|
|
|
|
arch|centos)
|
|
NGINX_INIT="/usr/bin/systemctl"
|
|
"$NGINX_INIT" start nginx || "$NGINX_INIT" reload nginx
|
|
;;
|
|
esac
|