Update Nginx configuration to integrate with existing setup

This commit is contained in:
boilerrat 2025-03-16 14:32:27 -04:00
parent 7a39abffd1
commit fcc192bd30
1 changed files with 11 additions and 61 deletions

View File

@ -20,18 +20,9 @@ fi
SSH_CMD="sshpass -p \"$SERVER_PASSWORD\" ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP"
SCP_CMD="sshpass -p \"$SERVER_PASSWORD\" scp -o StrictHostKeyChecking=no"
# Clean up existing configuration files
echo "Cleaning up existing configuration files..."
eval "$SSH_CMD \"rm -f /etc/nginx/sites-enabled/boilerhaus.org /etc/nginx/sites-enabled/boilerhaus.org.conf\""
eval "$SSH_CMD \"rm -f /etc/nginx/sites-available/boilerhaus.org /etc/nginx/sites-available/boilerhaus.org.conf\""
# Create backup of existing configuration
echo "Creating backup of existing configuration..."
eval "$SSH_CMD \"mkdir -p /etc/nginx/sites-available && cp -f /etc/nginx/sites-available/boilerhaus.org.conf /etc/nginx/sites-available/boilerhaus.org.conf.bak 2>/dev/null || true\""
# Create updated configuration file
# Create main website configuration file
echo "Creating main website configuration file..."
cat > boilerhaus.org.conf.new << 'EOL'
# Main website configuration
server {
listen 80;
listen [::]:80;
@ -66,50 +57,10 @@ server {
# 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..."
echo "Uploading main website configuration..."
eval "$SCP_CMD boilerhaus.org.conf.new $SERVER_USER@$SERVER_IP:/tmp/boilerhaus.org.conf.new"
eval "$SSH_CMD \"mv /tmp/boilerhaus.org.conf.new /etc/nginx/sites-available/boilerhaus.org.conf\""
@ -122,21 +73,20 @@ echo "Testing Nginx configuration..."
NGINX_TEST=$(eval "$SSH_CMD \"nginx -t 2>&1\"")
NGINX_TEST_EXIT_CODE=$?
# If the test is successful, start or reload Nginx
# If the test is successful, reload Nginx
if [ $NGINX_TEST_EXIT_CODE -eq 0 ]; then
echo "Starting or reloading Nginx..."
eval "$SSH_CMD \"systemctl is-active nginx || systemctl start nginx\""
eval "$SSH_CMD \"systemctl reload nginx || systemctl restart nginx\""
echo "Reloading Nginx..."
eval "$SSH_CMD \"systemctl reload nginx\""
echo "Configuration updated successfully!"
else
echo "Nginx configuration test failed. Restoring backup..."
echo "Nginx configuration test failed:"
echo "$NGINX_TEST"
eval "$SSH_CMD \"cp -f /etc/nginx/sites-available/boilerhaus.org.conf.bak /etc/nginx/sites-available/boilerhaus.org.conf 2>/dev/null || true\""
echo "Backup restored. Please check the configuration and try again."
echo "Please check the configuration and try again."
exit 1
fi
# Run Certbot to ensure SSL certificates are set up for all domains
# Run Certbot to ensure SSL certificates are set up for main domain
echo "Running Certbot to ensure SSL certificates are set up..."
eval "$SSH_CMD \"certbot --nginx --expand -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\""
eval "$SSH_CMD \"certbot --nginx -d boilerhaus.org -d www.boilerhaus.org -d cloud.boilerhaus.org --non-interactive --agree-tos --email admin@boilerhaus.org\""
echo "Done!"