Skip to content

Instantly share code, notes, and snippets.

@ynwd
Created January 15, 2025 10:12
Show Gist options
  • Save ynwd/e1a65043f3319736b88dc1a06042eec7 to your computer and use it in GitHub Desktop.
Save ynwd/e1a65043f3319736b88dc1a06042eec7 to your computer and use it in GitHub Desktop.
Installing Nginx and Certbot SSL certificate on GCP Compute Engine

Setup GCP Free Tier Compute Engine with Terrafom

# Prepare terraform installation
sudo apt-get update && sudo apt-get install -y gnupg software-properties-common

wget -O- https://apt.releases.hashicorp.com/gpg | \
gpg --dearmor | \
sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg > /dev/null

gpg --no-default-keyring \
--keyring /usr/share/keyrings/hashicorp-archive-keyring.gpg \
--fingerprint

echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] \
https://apt.releases.hashicorp.com $(lsb_release -cs) main" | \
sudo tee /etc/apt/sources.list.d/hashicorp.list

# Download the package information from HashiCorp.
sudo apt update

# Install terrafom
sudo apt-get install terraform

And then follow instruction of this repository: https://github.com/ynwd/awesome-compute-engine-terraform

Nginx and SSL Installation

# Ensure you have the latest versions of the software.
sudo apt update

# Install Nginx
sudo apt install nginx

# Start and Enable Nginx
sudo systemctl start nginx
sudo systemctl enable nginx

# Verify the Installation
sudo systemctl status nginx

# Install Certbot and the Nginx plugin:
sudo apt install certbot python3-certbot-nginx

# Obtain and install the SSL certificate:
sudo certbot --nginx -d play.fastro.dev

# Set Up Automatic Certificate Renewal
sudo certbot renew --dry-run

# Reload Nginx:
sudo systemctl reload nginx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment