Set up Nginx and Apache2 on Ubuntu with Self-Signed SSL/TLS Certificates
Below is a Bash script to download and set up Nginx server with SSL using a self-signed certificate and user-provided details: #
#!/bin/bash
# Check if the script is running with root privileges
if [; then
fi
# Check if a domain name is provided as an argument
if [; then
fi
# Assign the provided domain name to a variable
domain_name=""
# Prompt the user for SSL certificate details
# Update package lists
# Install Nginx
# Start Nginx service
# Enable Nginx to start on boot
# Check if Nginx is running
if ; then
else
fi
# Generate self-signed SSL certificate with user-provided details
# Configure Nginx to use SSL
# Create a symbolic link to enable the configuration
# Test Nginx configuration for syntax errors
# Reload Nginx to apply the changes
# Display the server IP address and open the default Nginx page in the browser
server_ip=
# Optionally, you can open the default Nginx page in the default web browser
# Uncomment the following line if you want to open the page automatically
# xdg-open "https://${domain_name}/"
Save the script to a file, for example, nginx_ssl_setup.sh. Make sure to give it executable permissions using the following command:
Then, run the script with root privileges and provide the domain name as an argument:
Replace example.com with your actual domain name. The script will prompt the user for SSL certificate details, update the package lists, install Nginx, start the Nginx service, generate a self-signed SSL certificate with the provided domain name and user-provided details, configure Nginx to use SSL for the specified domain, and display the server IP address along with the default Nginx page’s URL (with SSL). Optionally, you can uncomment the xdg-open line to automatically open the default Nginx page in the default web browser after installation. Remember that this self-signed certificate is not recommended for production use; use a valid SSL certificate from a trusted certificate authority for production deployments.
Below is a Bash script to download and set up Apache server with SSL using a self-signed certificate and user-provided details: #
#!/bin/bash
# Check if the script is running with root privileges
if [; then
fi
# Check if a domain name is provided as an argument
if [; then
fi
# Assign the provided domain name to a variable
domain_name=""
# Prompt the user for SSL certificate details
# Update package lists
# Install Apache
# Start Apache service
# Enable Apache to start on boot
# Check if Apache is running
if ; then
else
fi
# Generate self-signed SSL certificate with user-provided details
# Enable Apache SSL module and default site
# Reload Apache to apply the changes
# Display the server IP address and open the default Apache page in the browser
server_ip=
# Optionally, you can open the default Apache page in the default web browser
# Uncomment the following line if you want to open the page automatically
# xdg-open "https://${domain_name}/"
Save the script to a file, for example, apache_ssl_setup.sh. Make sure to give it executable permissions using the following command:
Then, run the script with root privileges and provide the domain name as an argument:
Replace example.com with your actual domain name. The script will prompt the user for SSL certificate details, update the package lists, install Apache, start the Apache service, generate a self-signed SSL certificate with the provided domain name and user-provided details, enable SSL module and default site, reload Apache to apply the changes, and display the server IP address along with the default Apache page’s URL (with SSL). Optionally, you can uncomment the xdg-open line to automatically open the default Apache page in the default web browser after installation. Remember that this self-signed certificate is not recommended for production use; use a valid SSL certificate from a trusted certificate authority for production deployments.