Skip to content

Add SSL setup script for Dockerized Nginx with Let's Encrypt#745

Open
udkumar wants to merge 6 commits intoBridgeconn:version-2from
udkumar:issue-459-auto-renewal-ssl-certificate
Open

Add SSL setup script for Dockerized Nginx with Let's Encrypt#745
udkumar wants to merge 6 commits intoBridgeconn:version-2from
udkumar:issue-459-auto-renewal-ssl-certificate

Conversation

@udkumar
Copy link
Contributor

@udkumar udkumar commented Nov 21, 2023

This commit introduces a new shell script for setting up and managing a Dockerised Nginx environment. Key features include:

  • Stopping/starting Nginx container
  • Freeing up port 80 on the host
  • Installing Nginx and Certbot if not present
  • Generating Let's Encrypt SSL certificates
  • Setting up automatic SSL certificate renewal
  • Copying SSL certificates to a specified Docker volume

The script is intended to streamline the deployment and maintenance of secure Nginx setups in Docker environments.

Copy link
Collaborator

@kavitharaju kavitharaju left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our existing setup we have nginx and certbot as docker services and we avoid installing them directly on the host machine. Please update this script to work with the docker services.

How/when to run this shell script? Please document necessary details.

@udkumar
Copy link
Contributor Author

udkumar commented Nov 21, 2023

I'm currently utilising Docker services exclusively and not using Nginx on the host.

I've automated the manual processes with a single shell script, which accomplishes the following tasks:

  1. Executes our Docker Compose based on the provided steps.
  2. Stops the Nginx container.
  3. Installs Nginx on the host and sets up SSL for a domain using Let's Encrypt with the aid of Certbot.
  4. Transfers the SSL certificate into a volume designated for the Nginx container.
  5. Then, it stops the host's Nginx service, which can also be removed if necessary.
  6. Finally, it restarts the Nginx container that was initially stopped in step 2

@udkumar
Copy link
Contributor Author

udkumar commented Nov 23, 2023

@kavitharaju
I have updated with the following changes:

  • No manual intervention is required.
  • The existing docker compose command (added in readme) will handle the SSL certificate and renew it automatically every 80 days.
  • I have modified the shell script to include only the relevant steps.

fi

# Configuration variables
NGINX_CONTAINER_NAME="docker-web-server-with-cert-1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to not hardcode this and get this from the env?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This we can take from env for sure

generate_certificates() {
echo "Generating SSL certificates for $DOMAIN..."

docker run --rm -it \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does this run docker within docker?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I also checked that the current approach isn't ideal. If it's not suitable, I'm working on creating a single Docker solution, though it's taking some time.

After your comment, I tried but I am getting the same issue as certificate not creating.

entrypoint: /bin/sh -c '
while :; do
/auto_ssl_script.sh;
sleep 80d;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to use the ofelia-scheduler which is already used for scheduled backups for this task?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants