warn "Unable to generate DH key exchange parameters - rolling back..."
mv-v /etc/nginx/ssl/dhp-4096.pem.old /etc/nginx/ssl/dhp-4096.pem || warn "Unable to generate new DH key exchage parameters nor to recover."
else
say "DH key exchange parameters was generated!"
fi
fi
say "Configuring nginx with SSL enabled..."
# Updating HTTPS config.
cat<<HERE > /etc/nginx/sites-available/greenlight
cat<<HERE > /etc/nginx/sites-available/greenlight
server_tokens off;
server_tokens off;
...
@@ -593,15 +638,32 @@ server {
...
@@ -593,15 +638,32 @@ server {
HERE
HERE
if! nginx -qs reload;then
# Validating new config
if! nginx -qt;then
# Rollback logic
warn "Something went wrong configuring nginx - attempting to recover..."
mv-v /etc/nginx/sites-available/greenlight /etc/nginx/sites-available/greenlight.https # Preserve used HTTPS config for admins.
mv-v /etc/nginx/sites-available/greenlight /etc/nginx/sites-available/greenlight.https # Preserve used HTTPS config for admins.
if mv-v /etc/nginx/sites-available/greenlight.old /etc/nginx/sites-available/greenlight;then
warn "Fallen back to previous configuration!"
else
cp-v /etc/nginx/sites-available/greenlight.http /etc/nginx/sites-available/greenlight # Preserve used HTTP config for admins while falling back to HTTP.
cp-v /etc/nginx/sites-available/greenlight.http /etc/nginx/sites-available/greenlight # Preserve used HTTP config for admins while falling back to HTTP.
nginx -qs reload
warn "No previous configuration was found - fallen back to http configuration!"
fi
err "Unable to configure nginx with certificates - if following the official guides then please contact the maintainers."
systemctl restart nginx
warn "Unable to configure nginx with certificates, retry to resolve."
return 1
fi
fi
say "Nginx was configured successuflly with SSL enabled!"
say "Nginx was configured successuflly with SSL enabled!"
systemctl restart nginx && say "Nginx is UP!"
return 0
}
}
# Given a container name as $1, this function will check if there's a match for that name in the list of running docker containers on the system.
# Given a container name as $1, this function will check if there's a match for that name in the list of running docker containers on the system.