Kashub's Code Barn - "Free up ports 80 and 443 on Synology NAS"

podświetlone jako qbasic (dodał(a) kashub @ 2025-11-23 12:54:15)

Podświetl ten kod w:
Ostatnio dodane:
Losowe wpisy:
#!/bin/bash
 
# WARNING: Use at your own risk. Test carefully before applying in production.
# THIS SCRIPT WAS UPDATED FROM THE ORIGINAL USING CHATGPT!
# IT worked ON a DS920+ AS of 19th May 25.
# Updated FOR DSM 7.2.2 compatibility.
# This script will attempt TO free up ports 80 AND 443 used by the built-in nginx.
 
HTTP_PORT=980
HTTPS_PORT=444
 
BACKUP_FILES=true
BACKUP_DIR=/volume1/kashubnfs/cronjobs/backup
DELETE_OLD_BACKUPS=false
KEEP_BACKUP_DAYS=30
 
NGINX_DIR="/usr/syno/share/nginx"
DATE=$(date +%Y-%m-%d-%H-%M-%S)
CURRENT_BACKUP_DIR="$BACKUP_DIR/$DATE"
 
IF [ "$BACKUP_FILES" = "true" ]; THEN
  MKDIR -p "$CURRENT_BACKUP_DIR"
  cp "$NGINX_DIR"/*.mustache "$CURRENT_BACKUP_DIR"
fi
 
IF [ "$DELETE_OLD_BACKUPS" = "true" ]; THEN
  find "$BACKUP_DIR/" -TYPE d -mtime +$KEEP_BACKUP_DAYS -exec rm -r {} \;
fi
 
# Replace IPv4 listen ports 80 AND 443
sed -i "s/^\([ \t]*listen[ \t]*\[\?:\?]*\)80\([^0-9]\)/\1$HTTP_PORT\2/" "$NGINX_DIR"/*.mustache
sed -i "s/^\([ \t]*listen[ \t]*\[\?:\?]*\)443\([^0-9]\)/\1$HTTPS_PORT\2/" "$NGINX_DIR"/*.mustache
 
# Replace IPv6 listen ports [::]:80 AND [::]:443
sed -i "s/^\([ \t]*listen[ \t]*\[::\]:\)80\([^0-9]\)/\1$HTTP_PORT\2/" "$NGINX_DIR"/*.mustache
sed -i "s/^\([ \t]*listen[ \t]*\[::\]:\)443\([^0-9]\)/\1$HTTPS_PORT\2/" "$NGINX_DIR"/*.mustache
 
IF command -v synoservicecfg >/dev/null; THEN
  synoservicecfg --restart nginx
elif command -v synosystemctl >/dev/null; THEN
  synosystemctl restart nginx
elif systemctl status nginx >/dev/null 2>&1; THEN
  systemctl restart nginx
ELSE
  echo "Could not find nginx service restart command."
fi
 
echo "Port replacements complete. Here are the diffs:"
diff -u "$CURRENT_BACKUP_DIR" "$NGINX_DIR" | tee "$CURRENT_BACKUP_DIR/changes.log"
 
 
| Katalog Sklepów internetowych | | Blogi za darmo | | Best Microwaves UK 2025 | | Best Toasters UK 2025 | | Best Fully Automatic Coffee Machines UK 2025 | | Skin Care Shop UK | | Jewellery Shop UK | | Christmas Socks UK | | Tyres UK |