# 🛠️ Kapitel 7 – Nextcloud (Tutorial, Nginx) --- ## Einleitung Nextcloud ist das Herzstück deiner privaten Cloud. Hier landen Dateien, Fotos, Kalender und Kontakte – ohne Google, ohne Microsoft. In diesem Kapitel installieren wir Nextcloud **in einem LXC-Container unter Proxmox**, setzen auf **PostgreSQL** als Datenbank, **Nginx + PHP-FPM** als Webserver und **Redis** als Cache. Die Benutzerdaten liegen auf einer separaten Festplatte – für Performance, Übersicht und Datensicherheit. --- ## Voraussetzungen * **Proxmox Host** mit 2 Platten (System + Datenplatte) * **LXC mit Ubuntu 24.04**, Nesting aktiviert * **Nginx Proxy Manager** für HTTPS-Zugriff * Eine **Domain**, die auf deinen Proxy zeigt * Container-Ressourcen: mind. 2 vCPU, 4 GB RAM * Grundwissen: Proxmox-GUI, SSH, Terminal --- ## Vorbereitung ### LXC-Container erstellen In der **Proxmox-GUI**: * CT-Name: `nextcloud` * Template: Ubuntu 24.04 LTS * CPU: 2+, RAM: 4–8 GB * **Nesting aktivieren** (unter „Optionen“) #### Zweite Festplatte direkt einhängen Beim Anlegen im Abschnitt „Disks“: * Mount Point: `/mnt/hdd` * Größe: z. B. `500` GB * Backup: deaktivieren Nach dem Start: ```bash ssh root@ ls -ld /mnt/hdd ``` → Gibt es das Verzeichnis? Dann ist alles korrekt eingebunden. --- ## Umsetzung ### System aktualisieren & Pakete installieren ```bash apt update && apt upgrade -y apt install -y nginx php-fpm php-gd php-imagick php-intl php-mbstring php-xml \ php-zip php-curl php-bz2 php-gmp php-pgsql php-redis redis-server \ postgresql unzip curl ``` --- ### Projektstruktur anlegen ```bash mkdir -p /srv/nextcloud/app mkdir -p /mnt/hdd/nextcloud_data chown -R www-data:www-data /mnt/hdd/nextcloud_data ``` --- ### Nextcloud herunterladen ```bash cd /srv/nextcloud/app curl -LO https://download.nextcloud.com/server/releases/latest.zip unzip latest.zip && rm latest.zip chown -R www-data:www-data nextcloud ``` --- ### PostgreSQL: Benutzer & Datenbank 🔸 WICHTIG: Wir nutzen **nur** `su - postgres`, daher ist **keine Änderung** an `pg_hba.conf` nötig! ```bash su - postgres psql ``` Dann in der PostgreSQL-Konsole: ```sql CREATE DATABASE nextcloud; CREATE USER nextcloud WITH PASSWORD 'DEIN_SICHERES_PASSWORT'; GRANT ALL PRIVILEGES ON DATABASE nextcloud TO nextcloud; \q ``` Zurück zur Shell: ```bash exit ``` Test (optional): ```bash psql -U nextcloud -h 127.0.0.1 -d nextcloud -W ``` Wenn du Zugriff bekommst → alles korrekt. --- ### PHP-FPM: Version prüfen ```bash ls /run/php/ ``` → z. B. `php8.3-fpm.sock` → merken --- ### Nginx konfigurieren ```bash nano /etc/nginx/sites-available/nextcloud.conf ``` ```nginx server { listen 80; server_name _; root /srv/nextcloud/app/nextcloud; index index.php index.html; client_max_body_size 10G; location = /robots.txt { allow all; log_not_found off; access_log off; } location ~ ^/(?:\.|autotest|occ|issue|indie|db_|console) { deny all; } location ~ \.php(?:$|/) { fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_pass unix:/run/php/php8.3-fpm.sock; # ggf. anpassen fastcgi_intercept_errors on; fastcgi_request_buffering off; } } ``` ```bash ln -s /etc/nginx/sites-available/nextcloud.conf /etc/nginx/sites-enabled/ nginx -t && systemctl reload nginx ``` --- ### NPM: Proxy Host einrichten Im Nginx Proxy Manager: * **Domain**: `cloud.deine-domain.tld` * **IP**: LXC-Adresse (z. B. `10.0.0.42`) * **Port**: 80 * **SSL aktivieren** (Let’s Encrypt) * **Force SSL** + **HTTP/2** aktivieren * **Advanced Tab** (optional, empfohlen): ``` client_max_body_size 10G; proxy_read_timeout 3600; proxy_send_timeout 3600; ``` --- ### Browser-Setup Im Browser: `https://cloud.deine-domain.tld` * Admin-Benutzer erstellen * Datenverzeichnis: `/mnt/hdd/nextcloud_data` * Datenbank: PostgreSQL → `127.0.0.1`, DB: `nextcloud`, User: `nextcloud`, Passwort: `DEIN_SICHERES_PASSWORT` --- ### config.php anpassen (Reverse Proxy + Redis) ```bash nano /srv/nextcloud/app/nextcloud/config/config.php ``` ```php 'trusted_domains' => ['cloud.DEINE-DOMAIN.tld'], 'overwrite.cli.url' => 'https://cloud.DEINE-DOMAIN.tld', 'overwritehost' => 'cloud.DEINE-DOMAIN.tld', 'overwriteprotocol' => 'https', 'trusted_proxies' => ['IP.DEINES.NPM'], 'filelocking.enabled' => true, 'memcache.local' => '\\OC\\Memcache\\Redis', 'memcache.locking' => '\\OC\\Memcache\\Redis', 'redis' => [ 'host' => '/var/run/redis/redis-server.sock', 'port' => 0, 'timeout' => 1.5, ], ``` Tipp: `www-data` sollte zur Gruppe `redis` gehören, sonst funktioniert File Locking nicht: ```bash usermod -aG redis www-data ``` --- ### PHP anpassen (für große Uploads & Performance) ```bash nano /etc/php/*/fpm/php.ini ``` ```ini upload_max_filesize = 10G post_max_size = 10G memory_limit = 1024M max_execution_time = 3600 output_buffering = 0 date.timezone = Europe/Berlin ``` ```bash systemctl reload php*-fpm ``` --- ### Cronjob aktivieren (Nextcloud Hintergrundjobs) ```bash crontab -u www-data -e ``` ```cron */5 * * * * php -f /srv/nextcloud/app/nextcloud/cron.php ``` --- ## Ergebnis * Nextcloud läuft im LXC, erreichbar via HTTPS * PostgreSQL-DB ist passwortgesichert & erreichbar * Daten liegen getrennt unter `/mnt/hdd/nextcloud_data` * Redis aktiv → keine File-Locking-Warnung * PHP tuned → große Uploads problemlos * Hintergrundjobs laufen automatisch --- ## Nächste Schritte * Vorheriges Kapitel: Vaultwarden * Weiter geht’s mit: Affine