From 255988d3dc721cd9ae6377a3d3e467967b1f5646 Mon Sep 17 00:00:00 2001 From: boilerrat <128boilerrat@gmail.com> Date: Sun, 16 Mar 2025 14:16:54 -0400 Subject: [PATCH] Add VPS setup scripts for domain configuration --- deploy-website.sh | 38 +++++++++++++ setup-vps.sh | 120 +++++++---------------------------------- update-nginx-config.sh | 111 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 101 deletions(-) create mode 100755 deploy-website.sh create mode 100755 update-nginx-config.sh diff --git a/deploy-website.sh b/deploy-website.sh new file mode 100755 index 0000000..f10b4d5 --- /dev/null +++ b/deploy-website.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# This script deploys the website to the VPS + +# Set variables +REMOTE_USER="root" +REMOTE_HOST="boilerhaus.org" +REMOTE_DIR="/var/www/boilerhaus.org" +LOCAL_DIR="." + +# Create a temporary directory for the website files +echo "Creating temporary directory..." +mkdir -p ./deploy-temp + +# Copy necessary files to the temporary directory +echo "Copying website files..." +cp -r index.html css dist ./deploy-temp/ + +# Create a tarball of the website files +echo "Creating tarball..." +tar -czf website.tar.gz -C ./deploy-temp . + +# Upload the tarball to the server +echo "Uploading to server..." +scp website.tar.gz $REMOTE_USER@$REMOTE_HOST:/tmp/ + +# Extract the tarball on the server +echo "Extracting files on server..." +ssh $REMOTE_USER@$REMOTE_HOST "mkdir -p $REMOTE_DIR && \ + tar -xzf /tmp/website.tar.gz -C $REMOTE_DIR && \ + chown -R www-data:www-data $REMOTE_DIR && \ + rm /tmp/website.tar.gz" + +# Clean up local files +echo "Cleaning up..." +rm -rf ./deploy-temp website.tar.gz + +echo "Website deployed successfully!" \ No newline at end of file diff --git a/setup-vps.sh b/setup-vps.sh index 0413030..ed6a718 100755 --- a/setup-vps.sh +++ b/setup-vps.sh @@ -1,107 +1,25 @@ #!/bin/bash -# This script helps set up your VPS for hosting your website and Nextcloud +# This script sets up the VPS with the correct Nginx configuration and deploys the website -# Check if we can connect to the VPS -echo "Testing connection to VPS..." -if ! ssh root@66.179.188.130 "echo 'Connection successful'"; then - echo "Failed to connect to VPS. Please check your SSH configuration." - exit 1 -fi +echo "=== Setting up VPS for boilerhaus.org ===" +echo "" -# Check if Nginx is installed -echo "Checking if Nginx is installed..." -if ! ssh root@66.179.188.130 "which nginx > /dev/null"; then - echo "Nginx is not installed. Installing..." - ssh root@66.179.188.130 "apt update && apt install -y nginx" -else - echo "Nginx is already installed." -fi +# Step 1: Update Nginx configuration +echo "Step 1: Updating Nginx configuration..." +./update-nginx-config.sh -# Check if Certbot is installed -echo "Checking if Certbot is installed..." -if ! ssh root@66.179.188.130 "which certbot > /dev/null"; then - echo "Certbot is not installed. Installing..." - ssh root@66.179.188.130 "apt update && apt install -y certbot python3-certbot-nginx" -else - echo "Certbot is already installed." -fi +# Step 2: Deploy website +echo "" +echo "Step 2: Deploying website..." +./deploy-website.sh -# Create directory for the website -echo "Creating directory for the website..." -ssh root@66.179.188.130 "mkdir -p /var/www/boilerhaus.org" - -# Create a temporary Nginx configuration without SSL -echo "Creating temporary Nginx configuration..." -cat > temp-boilerhaus.org.conf << EOF -server { - listen 80; - listen [::]:80; - server_name boilerhaus.org www.boilerhaus.org cloud.boilerhaus.org git.boilerhaus.org; - - root /var/www/boilerhaus.org; - index index.html; - - location / { - try_files \$uri \$uri/ =404; - } -} -EOF - -# Upload temporary Nginx configuration -echo "Uploading temporary Nginx configuration..." -scp temp-boilerhaus.org.conf root@66.179.188.130:/etc/nginx/sites-available/boilerhaus.org - -# Enable the site -echo "Enabling the site..." -ssh root@66.179.188.130 "ln -sf /etc/nginx/sites-available/boilerhaus.org /etc/nginx/sites-enabled/boilerhaus.org" - -# Restart Nginx with temporary configuration -echo "Restarting Nginx with temporary configuration..." -ssh root@66.179.188.130 "systemctl restart nginx" - -# Check for existing Nextcloud configuration -echo "Checking for existing Nextcloud configuration..." -if ssh root@66.179.188.130 "[ -d /var/www/nextcloud ]"; then - echo "Nextcloud directory found. Assuming Nextcloud is already installed." - - # Ask if user wants to move Nextcloud to cloud subdomain - read -p "Do you want to move Nextcloud to cloud.boilerhaus.org? (y/n): " move_nextcloud - if [[ $move_nextcloud == "y" ]]; then - echo "Updating Nextcloud configuration..." - ssh root@66.179.188.130 "sed -i 's/\"trusted_domains\".*$/\"trusted_domains\" => [\"cloud.boilerhaus.org\"],/' /var/www/nextcloud/config/config.php" - fi -else - echo "Nextcloud directory not found. Please install Nextcloud manually after setting up the domains." -fi - -# Check for Gitea port -echo "Checking if Gitea is running..." -if ssh root@66.179.188.130 "netstat -tuln | grep -q ':3000'"; then - echo "Gitea appears to be running on port 3000." -else - echo "Warning: Gitea doesn't seem to be running on the expected port (3000)." - echo "Please make sure Gitea is installed and running before proceeding." - read -p "Continue anyway? (y/n): " continue_anyway - if [[ $continue_anyway != "y" ]]; then - echo "Setup aborted. Please install and configure Gitea first." - exit 1 - fi -fi - -# Set up SSL certificates -echo "Setting up SSL certificates..." -ssh root@66.179.188.130 "certbot --nginx -d boilerhaus.org -d www.boilerhaus.org -d cloud.boilerhaus.org -d git.boilerhaus.org" - -# Now upload the final configuration with SSL -echo "Uploading final Nginx configuration with SSL..." -scp boilerhaus.org.conf root@66.179.188.130:/etc/nginx/sites-available/boilerhaus.org - -# Restart Nginx with final configuration -echo "Restarting Nginx with final configuration..." -ssh root@66.179.188.130 "systemctl restart nginx" - -# Clean up temporary file -rm temp-boilerhaus.org.conf - -echo "VPS setup complete!" \ No newline at end of file +echo "" +echo "=== Setup complete! ===" +echo "Your domains should now be configured as follows:" +echo "- boilerhaus.org → Main website" +echo "- bw.boilerhaus.org → Vaultwarden instance" +echo "- cloud.boilerhaus.org → Nextcloud dashboard" +echo "- git.boilerhaus.org → Gitea instance" +echo "" +echo "Please allow a few minutes for DNS changes to propagate." \ No newline at end of file diff --git a/update-nginx-config.sh b/update-nginx-config.sh new file mode 100755 index 0000000..bbb9aa1 --- /dev/null +++ b/update-nginx-config.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +# This script updates the Nginx configuration for boilerhaus.org and its subdomains + +# Create backup of existing configuration +echo "Creating backup of existing Nginx configuration..." +ssh root@boilerhaus.org "cp /etc/nginx/sites-available/boilerhaus.org.conf /etc/nginx/sites-available/boilerhaus.org.conf.bak" + +# Create updated configuration file +cat > boilerhaus.org.conf.new << 'EOL' +# Main website configuration +server { + listen 80; + listen [::]:80; + server_name boilerhaus.org www.boilerhaus.org; + + root /var/www/boilerhaus.org; + index index.html; + + location / { + try_files $uri $uri/ =404; + } + + # Managed by Certbot + # This section will be updated by Certbot automatically +} + +# Nextcloud configuration +server { + listen 80; + listen [::]:80; + server_name cloud.boilerhaus.org; + + # Proxy to Nextcloud + location / { + proxy_pass http://localhost:8080; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + # Managed by Certbot + # This section will be updated by Certbot automatically +} + +# Gitea configuration +server { + listen 80; + listen [::]:80; + server_name git.boilerhaus.org; + + # Proxy to Gitea + location / { + proxy_pass http://localhost:3000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + # Managed by Certbot + # This section will be updated by Certbot automatically +} + +# Vaultwarden configuration +server { + listen 80; + listen [::]:80; + server_name bw.boilerhaus.org; + + # Proxy to Vaultwarden + location / { + proxy_pass http://localhost:8000; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + # Managed by Certbot + # This section will be updated by Certbot automatically +} + +# SSL configurations will be added by Certbot automatically +EOL + +# Upload the new configuration +echo "Uploading new configuration..." +scp boilerhaus.org.conf.new root@boilerhaus.org:/etc/nginx/sites-available/boilerhaus.org.conf + +# Test Nginx configuration +echo "Testing Nginx configuration..." +ssh root@boilerhaus.org "nginx -t" + +# If the test is successful, reload Nginx +if [ $? -eq 0 ]; then + echo "Reloading Nginx..." + ssh root@boilerhaus.org "systemctl reload nginx" + echo "Configuration updated successfully!" +else + echo "Nginx configuration test failed. Restoring backup..." + ssh root@boilerhaus.org "cp /etc/nginx/sites-available/boilerhaus.org.conf.bak /etc/nginx/sites-available/boilerhaus.org.conf" + echo "Backup restored. Please check the configuration and try again." +fi + +# Run Certbot to ensure SSL certificates are set up for all domains +echo "Running Certbot to ensure SSL certificates are set up..." +ssh root@boilerhaus.org "certbot --nginx -d boilerhaus.org -d www.boilerhaus.org -d cloud.boilerhaus.org -d git.boilerhaus.org -d bw.boilerhaus.org --non-interactive --agree-tos --email admin@boilerhaus.org" + +echo "Done!" \ No newline at end of file