@echo "Deploying checked-in nginx config to $(VPS_HOST)..."
ssh -t $(VPS) "bash ~/.nginx-staging/deploy.sh"
+.PHONY: test/nginx
+test/nginx: ##H @Remote Test staged configuration without deploying
+ @echo "Testing staged config on $(VPS_HOST)..."
+ ssh -t $(VPS) "bash ~/.nginx-staging/deploy.sh test"
+
+.PHONY: certbot/nginx
+certbot/nginx: ##H @Remote Run certbot on remote VPS
+ @echo "Running certbot on $(VPS_HOST)..."
+ ssh -t $(VPS) "sudo certbot --nginx"
+
.PHONY: stage/local
stage/local: ##H @Local Stage files locally (supports SUDO_USER)
ifdef SUDO_USER
@echo "Deploying locally..."
bash ~/.nginx-staging/deploy.sh
endif
+
+.PHONY: test/local
+test/local: stage/local ##H @Local Test staged configuration locally (supports SUDO_USER)
+ifdef SUDO_USER
+ @echo "Testing locally as $(SUDO_USER)..."
+ su -P $(SUDO_USER) -c "bash /tmp/nginx-staging/deploy.sh test"
+else
+ @echo "Testing locally..."
+ bash ~/.nginx-staging/deploy.sh test
+endif
+
+.PHONY: certbot/local
+certbot/local: ##H @Local Run certbot locally (supports SUDO_USER)
+ifdef SUDO_USER
+ @echo "Running certbot locally as $(SUDO_USER)..."
+ su -P $(SUDO_USER) -c "sudo certbot --nginx"
+else
+ @echo "Running certbot locally..."
+ sudo certbot --nginx
+endif
+
+.PHONY: certbot/list-certs
+certbot/list-certs: ##H @Local List managed certificates (supports SUDO_USER)
+ifdef SUDO_USER
+ @echo "Listing certificates as $(SUDO_USER)..."
+ su -P $(SUDO_USER) -c "sudo certbot certificates"
+else
+ @echo "Listing certificates..."
+ sudo certbot certificates
+endif
exit 0
fi
+if [ "$1" = "test" ]; then
+ echo "Running pre-flight validation on staged config..."
+ TMP_NGINX_CONF=$(mktemp)
+
+ # Create a temporary nginx.conf that points to STAGING_DIR instead of /etc/nginx/conf.d
+ # We assume the standard include is "/etc/nginx/conf.d/*.conf"
+ # We strictly replace that string with our staging path.
+ sed "s|/etc/nginx/conf.d/\*\.conf|$STAGING_DIR/*.conf|g" /etc/nginx/nginx.conf >"$TMP_NGINX_CONF"
+
+ if sudo nginx -t -c "$TMP_NGINX_CONF"; then
+ echo "✓ Pre-flight validation passed."
+ # Run debug dump by default for test target
+ sudo nginx -T -c "$TMP_NGINX_CONF"
+ rm "$TMP_NGINX_CONF"
+ exit 0
+ else
+ echo "✗ Pre-flight validation FAILED."
+ rm "$TMP_NGINX_CONF"
+ exit 1
+ fi
+fi
+
# Create timestamped backup
BACKUP_DIR=~/nginx_backup_$(date +%s)
echo "Creating backup at $BACKUP_DIR..."