I invite everyone to utilize my Docker Swarm script, designed for multi-domain management.
download link: https://bitbucket.org/alon911/multi-domain-deployer/src/master/
How to Use the Python Docker & Nginx Configuration Script
This guide provides instructions on how to run the Python script to configure Docker, Nginx, and Certbot for managing static and WordPress sites. The script uses domain information from a .env
file to generate Docker Compose configurations, Nginx server blocks, and SSL certificates with Certbot.
- Setting Up the .env File
Create a.env
file in the same directory as the Python script. This file will contain configurations for each domain you want to manage, including site type and SSL details.
Here’s an example of what your.env
file should look like:
CERTBOT_EMAIL=your-email@example.com
DOMAIN=example.com
SITE_TYPE=static
WWW=true
NON_WWW=true
DOMAIN=anotherdomain.com
SITE_TYPE=wordpress
WWW=false
NON_WWW=true
• Explanation of each key in the .env
file:
• CERTBOT_EMAIL: The email address for Certbot SSL certificate registration.
• DOMAIN: The domain name for your site.
• SITE_TYPE: Set to either 'static' or 'wordpress' depending on the type of site.
• WWW and NON_WWW: Boolean values (true or false) to indicate whether the www or non-www version of the domain should be supported.
2. Running the Script
Open a terminal in the directory containing your Python script and .env
file, then run the script with the following command:
python your_script.py
- Script Capabilities
The script performs the following actions: - Loads Domain Configurations: Reads domain information from the
.env
file. - Creates Required Directories: Ensures that necessary directories exist for each domain, based on its type (static or WordPress).
- Generates SSL Certificates: Uses Certbot to generate SSL certificates for each domain.
- Creates Nginx Configuration: Generates Nginx server block configuration files for each domain, including SSL configurations.
- Generates Docker Compose File: Creates a Docker Compose file that dynamically configures services for each domain.
- Generated Output
Once the script has completed, the following files and directories will be created:
• 1. Nginx Configurations: For each domain, a separate Nginx configuration file will be created in thenginx/generated
directory.
• 2. SSL Certificates: Certbot will create SSL certificates in/etc/letsencrypt
.
• 3. Docker Compose File: Adocker-compose.yml
file will be generated to launch Nginx and WordPress services as defined. - Starting the Docker Containers
To start the Docker containers using the generated Docker Compose file, run:
docker-compose up -d
This command starts the containers in detached mode, running Nginx as a reverse proxy and creating WordPress instances as needed.
6. Additional Notes
Make sure that Docker and Docker Compose are installed on your system before running this script. For WordPress sites, ensure that MySQL environment variables are set correctly in the generated docker-compose.yml
file.