Files

631 lines
15 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 🛠️ Kapitel 7 Nextcloud (Nginx + PostgreSQL + Redis, NPM-Setup)
> [!INFO]
> Dieses Kapitel ist eine vorbereitete Rohfassung. Es enthält bereits alle technischen Schritte in korrekter Reihenfolge. Die Blogtexte und Erklärungen folgen später.
## ✨ Einleitung
[Platzhalter für Einstiegstext:
Was ist Nextcloud, warum ist es sinnvoll, was kann man damit tun.
Hinweis auf Unabhängigkeit von Google & Co., Einsatz als Streamer, für Teamsharing etc.]
## 📋 Voraussetzungen
[Platzhalter für grafische Checkliste oder Übersicht: z.B. Screenshot LXC-Übersicht]
- Proxmox-Host mit 2 Platten (System + Daten)
- LXC mit Ubuntu24.04, „Nesting“ aktiviert
- Nginx Proxy Manager (NPM) läuft bereits
- Domain zeigt korrekt auf den Proxy
- Container-Ressourcen: 2 vCPU, 48GB RAM
- Grundkenntnisse in Proxmox, SSH, Terminal
## ⚙️ LXC-Container anlegen
**In der Proxmox-GUI:**
- CT-Name: `nextcloud`
- Template: `Ubuntu 24.04 LTS`
- CPU: 2+, RAM: 4096+ MB
- „Nesting“ aktivieren (unter „Optionen“)
**Zweite Festplatte direkt einbinden:**
- Mount Point: `/mnt/hdd`
- Größe: z.B. `500` GB
- Backup: deaktivieren
Nach dem Start:
```bash
ssh root@<IP-des-Containers>
ls -ld /mnt/hdd
```
→ Wenn ein gültiges Verzeichnis erscheint, ist alles korrekt gemountet.
## 📦 System vorbereiten
[Platzhalter: Warum update & Basis-Tools wichtig sind]
```bash
apt update && apt upgrade -y
apt install -y curl gnupg2 ca-certificates lsb-release apt-transport-https software-properties-common unzip nano sudo gnupg
```
## 🌐 Dienste installieren
[Platzhalter: Warum explizites PHP-Repo nötig ist (Ubuntu 24.04 enthält nicht alle Module).
Verweis auf Ondřej Surý PPA Standard bei professionellen PHP-Deployments.]
### Dienste + PHP 8.3 + Module installieren
```bash
apt install -y nginx redis-server postgresql php8.3-fpm php8.3-pgsql php8.3-cli php8.3-common php8.3-gd php8.3-mbstring php8.3-xml php8.3-zip php8.3-curl php8.3-bz2 php8.3-intl php8.3-gmp php8.3-imagick php8.3-redis
```
## 📁 Verzeichnisse anlegen
```bash
mkdir -p /srv/nextcloud/app
mkdir -p /mnt/hdd/nextcloud_data
chown -R www-data:www-data /mnt/hdd/nextcloud_data
chmod 750 /mnt/hdd/nextcloud_data
```
## ⚙️ PHP konfigurieren
### `php.ini` (globale Werte)
```bash
nano /etc/php/8.3/fpm/php.ini
```
```ini
upload_max_filesize = 10G
post_max_size = 10G
memory_limit = 1024M
max_execution_time = 3600
max_input_time = 3600
date.timezone = Europe/Berlin
opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.interned_strings_buffer=16
```
### `www.conf` (Pool-Konfiguration)
```bash
nano /etc/php/8.3/fpm/pool.d/www.conf
```
```ini
pm = dynamic
pm.max_children = 12
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 6
```
PHP-FPM neu laden:
```bash
systemctl reload php8.3-fpm
```
## 🐘 PostgreSQL initialisieren (für LXC)
```bash
pg_dropcluster 16 main --stop
pg_createcluster 16 main --start
systemctl enable postgresql
systemctl start postgresql
```
Zugang zur DB:
```bash
su - postgres
```
Datenbank anlegen:
```sql
psql
CREATE DATABASE nextcloud;
CREATE USER nextcloud WITH PASSWORD 'DEIN_SICHERES_PASSWORT';
GRANT ALL PRIVILEGES ON DATABASE nextcloud TO nextcloud;
\q
```
```sql
psql -d nextcloud
-- Zugriff auf public erlauben
GRANT ALL ON SCHEMA public TO nextcloud;
-- Und Ownership auf den Nutzer übertragen
ALTER SCHEMA public OWNER TO nextcloud;
```
Dann wieder raus:
```bash
exit
```
## 🔄 Redis konfigurieren
[Platzhalter: Warum Redis wichtig ist (Caching, File Locking, keine APCu mehr).
Nur lokal via Socket, daher keine Authentifizierung nötig.]
### Redis-Zugriffsrechte setzen
```bash
usermod -aG redis www-data
```
> [!NOTE]
> Dadurch kann der Webserver-User (`www-data`) auf den Redis-Socket zugreifen.
### Redis-Konfiguration prüfen
```bash
nano /etc/redis/redis.conf
```
Die folgenden Zeilen sollten gesetzt sein (oder geändert werden):
```ini
supervised systemd
unixsocket /var/run/redis/redis-server.sock
unixsocketperm 770
```
> [!TIP]
> Weitere Einstellungen wie `bind` oder `requirepass` brauchst du **nicht**,
> solange du Redis **nur lokal über den Socket** nutzt.
Redis neu starten:
```bash
systemctl restart redis-server
systemctl restart php8.3-fpm
```
---
Fertig. Jetzt ist Redis bereit für Nextcloud Caching und Locking funktionieren nach dem Setup automatisch,
wenn wir die Einträge in der `config.php` ergänzen.
## ⬇️ Nextcloud herunterladen
[Platzhalter: Warum wir Nextcloud manuell installieren (Version kontrollieren, Updates nachvollziehbar, keine Snap/FPM-Probleme).]
### Download & Entpacken
```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
```
> [!NOTE]
> Aktuelle Version prüfen: https://nextcloud.com/changelog/
---
## ⚙️ `config.php` vorbereiten
[Platzhalter: Warum wir die Datei *vorher* anlegen (Proxy-Erkennung, Redis, saubere Setup-Erfahrung).
Wird beim ersten Aufruf automatisch ergänzt.]
### Datei erstellen
```bash
nano /srv/nextcloud/app/nextcloud/config/config.php
```
### Inhalt einfügen
```php
<?php
$CONFIG = array (
'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,
],
);
```
```bash
chown -R www-data:www-data /srv/nextcloud/app/nextcloud/config
```
> [!TIP]
> `trusted_proxies` kann z.B. `10.0.0.1` sein, wenn NPM im selben Netz läuft.
> Mehrere Proxies können als Array ergänzt werden.
---
Damit ist Nextcloud bereit gleich folgt der Abschnitt zur **Nginx-Konfiguration**.
## 🌐 Nginx konfigurieren (vHost intern)
[Platzhalter: Warum wir keinen HTTPS/SSL im Container brauchen (TLS wird von NPM übernommen).
Nginx hier nur als lokaler Webserver für PHP-FPM + Nextcloud.]
### Neue Konfigurationsdatei anlegen
```bash
nano /etc/nginx/sites-available/nextcloud.conf
```
### Inhalt einfügen
```nginx
server {
listen 80;
server_name cloud.DEINE-DOMAIN.tld;
root /srv/nextcloud/app/nextcloud;
index index.php index.html;
client_max_body_size 10G;
fastcgi_buffers 64 4K;
add_header Referrer-Policy "no-referrer" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ ^/(?:\.htaccess|data|config|db_structure\\.xml|README) {
deny all;
}
location ~ \\.php(?:$|/) {
include fastcgi_params;
fastcgi_split_path_info ^(.+\\.php)(/.*)$;
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;
fastcgi_intercept_errors on;
fastcgi_request_buffering off;
}
}
```
### Site aktivieren
```bash
ln -s /etc/nginx/sites-available/nextcloud.conf /etc/nginx/sites-enabled/
rm /etc/nginx/sites-enabled/default
nginx -t && systemctl reload nginx
```
> [!NOTE]
> `nginx -t` prüft die Konfiguration. Nur wenn „syntax is ok“ erscheint, darfst du reloaden.
---
Sobald das erledigt ist, folgt der Abschnitt für **NPMProxy + Domain-Setup**.
Sag einfach, wann du soweit bist oder wenn du auf ein Problem triffst.
## 🌍 NPM-Proxy konfigurieren
[Platzhalter: Warum wir Nginx Proxy Manager verwenden (TLS-Termination, zentraler Reverse Proxy, Lets Encrypt, Portweiterleitung).
Nextcloud selbst kennt nur HTTP und läuft im LXC ohne Zertifikat.]
### Im Nginx Proxy Manager (Web-GUI):
1. Gehe auf **Hosts → Proxy Hosts → Add Proxy Host**
2. Trage ein:
| Feld | Wert |
|-----------------------|---------------------------------|
| **Domain Names** | `cloud.DEINE-DOMAIN.tld` |
| **Forward Hostname/IP** | `<IP deines Nextcloud-LXC>` |
| **Forward Port** | `80` |
| **Access** | Websockets aktivieren ✅ |
| **SSL** | → **Request a new SSL Certificate**
| | → **Force SSL** aktivieren ✅
| | → **HTTP/2 Support** aktivieren ✅
> [!TIP]
> Trage bei „E-Mail“ eine gültige Adresse ein, sonst schlägt das Zertifikat fehl.
> HSTS kannst du bei Bedarf aktivieren (empfohlen).
### (Optional) Für große Uploads:
Reiter „Advanced“:
```nginx
client_max_body_size 10G;
proxy_read_timeout 3600;
proxy_send_timeout 3600;
```
---
**Jetzt testen:**
Öffne im Browser:
```
https://cloud.DEINE-DOMAIN.tld
```
Du solltest den **Nextcloud-Setup-Assistenten** sehen ohne Fehlermeldung, ohne Mixed Content.
Falls du eine Nginx-Standardseite siehst: Proxy nicht korrekt → prüfe Domain, IP und Port.
---
## ⏱️ Cronjob für Hintergrundprozesse
Nextcloud erledigt viele Aufgaben im Hintergrund z.B. Vorschaugenerierung, Datei-Indexierung, etc.
Diese Jobs laufen am zuverlässigsten per Cron.
### Cron für `www-data` anlegen:
```bash
crontab -u www-data -e
```
→ Eintrag ganz unten einfügen:
```cron
*/5 * * * * php -f /srv/nextcloud/app/nextcloud/cron.php
```
> Bedeutet: Alle 5 Minuten wird das Skript `cron.php` ausgeführt.
Speichern: `STRG+O`, Enter
Beenden: `STRG+X`
---
## 🌐 Nextcloud im Browser einrichten
Rufe deine Instanz im Browser auf:
```
https://cloud.DEINE-DOMAIN.tld
```
Du siehst nun das Setup-Formular von Nextcloud.
### ⚙️ Setup-Einstellungen
Trage folgende Werte ein:
**Admin-Zugang:**
- Benutzername: frei wählbar
- Passwort: stark wählen
**Datenverzeichnis:**
```
/mnt/hdd/nextcloud_data
```
**Datenbank:**
- Typ: **PostgreSQL**
- Benutzer: `nextcloud`
- Passwort: `DEIN_SICHERES_PASSWORT`
- Datenbankname: `nextcloud`
- Host: `localhost`
> ⚠️ Wichtig: Wenn Nextcloud sich nicht mit der Datenbank verbinden kann, prüfe `config.php`, Datenbankrechte oder ob der PostgreSQL-Dienst läuft.
---
###Feinschliff & Optimierung
Nach der Grundinstallation erscheinen im Admin-Panel oft Hinweise.
Diese sind kein Fehler, sondern Empfehlungen, um die Instanz stabil, sicher und performant zu machen.
Wir gehen sie jetzt Schritt für Schritt durch.
---
Schritt: MIME-Type für .mjs aktivieren
Ziel: Browser können moderne JavaScript-Dateien korrekt laden. Ohne das brechen manche Nextcloud-Apps ab.
Anleitung:
* Datei öffnen: nano /etc/nginx/sites-available/nextcloud.conf
* Innerhalb des server { ... }-Blocks einfügen:
types { application/javascript mjs; }
* Konfiguration testen und neu laden: nginx -t && systemctl reload nginx
Prüfen:
* Im Admin-Panel verschwindet die Meldung.
* Im Browser (F12 → Netzwerk) ist application/javascript als MIME-Type sichtbar.
---
Schritt: /ocm-provider/ und ocs-provider auflösen
Ziel: Externe Freigaben und Federation funktionieren.
Anleitung:
* In derselben Datei (nextcloud.conf) hinzufügen:
location \~ ^/(?\:ocm-provider|ocs-provider)/ { try\_files \$uri \$uri/ =404; index index.php; }
* Danach Nginx neu laden: nginx -t && systemctl reload nginx
Prüfen:
* Admin-Meldung verschwindet.
* Aufruf von [https://cloud.DEINE-DOMAIN.tld/ocm-provider/](https://cloud.DEINE-DOMAIN.tld/ocm-provider/) zeigt kein Nginx-404 mehr.
---
Schritt: .well-known Weiterleitungen
Ziel: Federation, CalDAV, CardDAV und WebFinger funktionieren.
Anleitung:
* In nextcloud.conf unterhalb des server { ... }-Blocks ergänzen:
location = /.well-known/webfinger { return 301 /index.php/.well-known/webfinger; }
location = /.well-known/nodeinfo { return 301 /index.php/.well-known/nodeinfo; }
location ^\~ /.well-known/acme-challenge { default\_type "text/plain"; root /var/www/letsencrypt; }
location = /.well-known/carddav { return 301 /remote.php/dav; }
location = /.well-known/caldav { return 301 /remote.php/dav; }
* Neu laden: nginx -t && systemctl reload nginx
Prüfen:
* Meldung im Adminbereich verschwindet.
* Test: curl -I [https://cloud.DEINE-DOMAIN.tld/.well-known/carddav](https://cloud.DEINE-DOMAIN.tld/.well-known/carddav) → liefert 301.
---
Schritt: Debug-Mode deaktivieren
Ziel: Produktivbetrieb ohne unnötige Fehlerausgaben.
Anleitung:
* Datei öffnen: nano /srv/nextcloud/app/nextcloud/config/config.php
* Sicherstellen, dass folgende Zeile existiert: 'debug' => false,
Prüfen:
* Adminpanel zeigt nicht mehr „Debug-Modus aktiv“.
---
Schritt: Wartungsfenster setzen
Ziel: Ressourcenintensive Tasks laufen nachts.
Anleitung:
sudo -u www-data php /srv/nextcloud/app/nextcloud/occ config\:system\:set maintenance\_window\_start --value="2"
Prüfen:
* Adminbereich zeigt kein Warnsymbol mehr.
---
Schritt: MIME-Type Migration
Ziel: Neueste Dateitypen sind registriert.
Anleitung:
sudo -u www-data php /srv/nextcloud/app/nextcloud/occ maintenance\:repair --include-expensive
Prüfen:
* Meldung „MIME-Type-Migration verfügbar“ verschwindet.
---
Schritt: Fehlende Indizes
Ziel: Datenbankabfragen werden schneller.
Anleitung:
sudo -u www-data php /srv/nextcloud/app/nextcloud/occ db\:add-missing-indices
Prüfen:
* Keine Admin-Warnung mehr zu Indizes.
---
Schritt: PATH-Variable für PHP
Ziel: Systembefehle werden korrekt gefunden.
Anleitung:
* Datei öffnen: nano /etc/php/8.3/fpm/pool.d/[www.conf](http://www.conf)
* Am Ende ergänzen: env\[PATH] = /usr/local/bin:/usr/bin:/bin
* Neu laden: systemctl reload php8.3-fpm
Prüfen:
* Meldung zu getenv("PATH") verschwindet.
---
Schritt: Standard-Telefonregion
Ziel: Telefonnummern ohne Vorwahl validieren.
Anleitung:
* In config.php einfügen: 'default\_phone\_region' => 'DE',
Prüfen:
* Adminpanel zeigt keinen Hinweis mehr.
---
Schritt: Mailserver einrichten
Ziel: System kann Benachrichtigungen verschicken.
Anleitung (Beispiel SMTP):
* In config.php eintragen:
'mail\_smtpmode' => 'smtp',
'mail\_smtpsecure' => 'tls',
'mail\_sendmailmode' => 'smtp',
'mail\_from\_address' => 'nextcloud',
'mail\_domain' => 'deine-domain.tld',
'mail\_smtphost' => 'mail.deine-domain.tld',
'mail\_smtpport' => '587',
'mail\_smtpauth' => 1,
'mail\_smtpname' => '[user@deine-domain.tld](mailto:user@deine-domain.tld)',
'mail\_smtppassword' => 'PASSWORT'
* Alternativ per Web-UI → Einstellungen → Grundeinstellungen → E-Mail-Server
Prüfen:
* Testmail versenden.
* Adminhinweis verschwindet.
---
Schritt: Imagick mit SVG-Support
Ziel: Bessere Bildvorschauen.
Anleitung:
apt install -y libmagickcore-6.q16-6-extra
systemctl restart php8.3-fpm
Prüfen:
* Adminmeldung zu SVG verschwindet.
---
### Ergebnis
Nach diesen Schritten ist die Instanz vollständig optimiert:
* Keine Warnmeldungen mehr
* Volle Performance durch Indizes + Redis
* Sichere Produktion (kein Debug, sauberes Wartungsfenster)
* Alle Nextcloud-Apps funktionieren fehlerfrei