Files
Homelab--Bratonein-Kontroll…/Kapitel 7/Tutorial.md

365 lines
8.6 KiB
Markdown
Raw 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: Hinweis auf explizite PHP-Version, warum kein „php-*“ verwendet wird]
```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
```
## ⚙️ 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
```
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
```
---
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/nextcloud-29.0.1.zip
unzip nextcloud-29.0.1.zip && rm nextcloud-29.0.1.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,
],
);
```
> [!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.
---