Difference between revisions of "NextCloud"
Jump to navigation
Jump to search
Rafahsolis (talk | contribs) (Created page with "=== Install with docker compose === docker-compose.yml:<syntaxhighlight lang="yaml"> version: '3.8' services: nextcloud: image: nextcloud:latest container_name: nex...") Tag: visualeditor |
Rafahsolis (talk | contribs) Tag: visualeditor |
||
| Line 1: | Line 1: | ||
| − | === Install with docker compose === | + | ===Install with docker compose=== |
docker-compose.yml:<syntaxhighlight lang="yaml"> | docker-compose.yml:<syntaxhighlight lang="yaml"> | ||
version: '3.8' | version: '3.8' | ||
| Line 81: | Line 81: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | ==== Create subfolder structure ==== | + | ====Create subfolder structure==== |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
sudo mkdir -p /mnt/nextcloud/{nextcloud,data,db,redis,caddy/data,caddy/config} | sudo mkdir -p /mnt/nextcloud/{nextcloud,data,db,redis,caddy/data,caddy/config} | ||
| Line 91: | Line 91: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | ==== Start NextCloud ==== | + | ====Start NextCloud==== |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
docker compose up --detach | docker compose up --detach | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | ==== Assing file permissions ==== | + | ====Assing file permissions==== |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
docker exec -it nextcloud chown -R www-data:www-data /var/www/html | docker exec -it nextcloud chown -R www-data:www-data /var/www/html | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | ==== Format Cadyfile ==== | + | ====Format Cadyfile==== |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
docker compose exec caddy caddy fmt --overwrite /etc/caddy/Caddyfile | docker compose exec caddy caddy fmt --overwrite /etc/caddy/Caddyfile | ||
docker compose restart caddy | docker compose restart caddy | ||
| + | </syntaxhighlight><br /> | ||
| + | |||
| + | ==== Edit config.php ==== | ||
| + | |||
| + | ===== Find out caddy container network: ===== | ||
| + | <syntaxhighlight lang="bash"> | ||
| + | docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nextcloud_caddy | ||
| + | </syntaxhighlight>wil return something like 172.18.0.4<syntaxhighlight lang="php"> | ||
| + | 'overwritehost' => 'cloud.herrerosolis.com', | ||
| + | 'overwriteprotocol' => 'https', | ||
| + | 'trusted_proxies' => ['172.18.0.0/16'], # Use real caddy Docker network here | ||
| + | 'forwarded_for_headers' => ['HTTP_X_FORWARDED_FOR'], | ||
| + | </syntaxhighlight><syntaxhighlight lang="bash"> | ||
| + | docker compose restart nextcloud | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | === NextCloud Install Script === | + | ===NextCloud Install Script=== |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
#!/bin/bash | #!/bin/bash | ||
| Line 233: | Line 247: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | == Verify security config == | + | ==Verify security config== |
https://cloud.herrerosolis.com/index.php/settings/admin/overview | https://cloud.herrerosolis.com/index.php/settings/admin/overview | ||
| − | === Allow big file upload === | + | ===Allow big file upload=== |
php.ini:<syntaxhighlight lang="ini"> | php.ini:<syntaxhighlight lang="ini"> | ||
upload_max_filesize = 2G | upload_max_filesize = 2G | ||
| Line 244: | Line 258: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
| − | == Backups == | + | ==Backups== |
The important paths to backup are: | The important paths to backup are: | ||
| − | * <code>/mnt/nextcloud/db</code> (PostgreSQL) | + | *<code>/mnt/nextcloud/db</code> (PostgreSQL) |
| − | * <code>/mnt/nextcloud/data</code> (tus archivos) | + | *<code>/mnt/nextcloud/data</code> (tus archivos) |
| − | * <code>/mnt/nextcloud/nextcloud</code> (archivos de Nextcloud + apps instaladas) | + | *<code>/mnt/nextcloud/nextcloud</code> (archivos de Nextcloud + apps instaladas) |
| − | * <code>/mnt/nextcloud/caddy</code> (configuración SSL + Caddyfile) | + | *<code>/mnt/nextcloud/caddy</code> (configuración SSL + Caddyfile) |
<br /> | <br /> | ||
| − | == Updates == | + | ==Updates== |
<syntaxhighlight lang="bash"> | <syntaxhighlight lang="bash"> | ||
docker compose pull | docker compose pull | ||
docker compose up -d | docker compose up -d | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Latest revision as of 19:56, 26 August 2025
Install with docker compose[edit]
docker-compose.yml:
version: '3.8'
services:
nextcloud:
image: nextcloud:latest
container_name: nextcloud
restart: unless-stopped
ports:
- 8080:80 # interno, solo para Caddy
volumes:
- /mnt/nextcloud/nextcloud:/var/www/html
- /mnt/nextcloud/data:/var/www/html/data
depends_on:
- db
- redis
environment:
- POSTGRES_HOST=db
- POSTGRES_DB=nextcloud
- POSTGRES_USER=nextcloud
- POSTGRES_PASSWORD=secret
- REDIS_HOST=redis
- NEXTCLOUD_ADMIN_USER=admin
- NEXTCLOUD_ADMIN_PASSWORD=admin123
- NEXTCLOUD_TRUSTED_DOMAINS=cloud.herrerosolis.com
- NEXTCLOUD_OVERWRITEHOST=cloud.herrerosolis.com
- NEXTCLOUD_OVERWRITEPROTOCOL=https
db:
image: postgres:15
container_name: nextcloud_db
restart: unless-stopped
volumes:
- /mnt/nextcloud/db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=nextcloud
- POSTGRES_USER=nextcloud
- POSTGRES_PASSWORD=secret
redis:
image: redis:alpine
container_name: nextcloud_redis
restart: unless-stopped
volumes:
- /mnt/nextcloud/redis:/data
caddy:
image: greenpau/caddy-cloudflare:latest
container_name: nextcloud_caddy
restart: unless-stopped
ports:
- 443:443
volumes:
- /mnt/nextcloud/caddy/Caddyfile:/etc/caddy/Caddyfile
- /mnt/nextcloud/caddy/data:/data
- /mnt/nextcloud/caddy/config:/config
environment:
- CLOUDFLARE_API_TOKEN=${CLOUDFLARE_API_TOKEN}
depends_on:
- nextcloud
networks:
default:
name: nextcloud_net
/mnt/nextcloud/caddy/Caddyfile:
cloud.herrerosolis.com {
reverse_proxy nextcloud:80
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
}
encode gzip
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
}
}
Create subfolder structure[edit]
sudo mkdir -p /mnt/nextcloud/{nextcloud,data,db,redis,caddy/data,caddy/config}
sudo chown -R root:root /mnt/nextcloud
sudo chmod -R 755 /mnt/nextcloud
cd ${DOCKER_COMPOSE_DIRECTORY}
echo 'CLOUDFLARE_API_TOKEN=tu_token_de_cloudflare' > .env
Start NextCloud[edit]
docker compose up --detach
Assing file permissions[edit]
docker exec -it nextcloud chown -R www-data:www-data /var/www/html
Format Cadyfile[edit]
docker compose exec caddy caddy fmt --overwrite /etc/caddy/Caddyfile
docker compose restart caddy
Edit config.php[edit]
Find out caddy container network:[edit]
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nextcloud_caddy
wil return something like 172.18.0.4
'overwritehost' => 'cloud.herrerosolis.com',
'overwriteprotocol' => 'https',
'trusted_proxies' => ['172.18.0.0/16'], # Use real caddy Docker network here
'forwarded_for_headers' => ['HTTP_X_FORWARDED_FOR'],
docker compose restart nextcloud
NextCloud Install Script[edit]
#!/bin/bash
set -e
echo "🔁 Deteniendo contenedores previos..."
docker compose down || true
echo "🧹 Borrando volúmenes de datos antiguos..."
sudo rm -rf /mnt/nextcloud/{db,data,nextcloud,redis,caddy/data,caddy/config}
echo "📁 Creando estructura de carpetas..."
sudo mkdir -p /mnt/nextcloud/{db,data,nextcloud,redis,caddy/data,caddy/config}
sudo chown -R $USER:$USER /mnt/nextcloud
echo "📄 Generando docker-compose.yml..."
cat > docker-compose.yml <<EOF
version: '3.8'
services:
nextcloud:
image: nextcloud:latest
container_name: nextcloud
restart: unless-stopped
ports:
- 8080:80
volumes:
- /mnt/nextcloud/nextcloud:/var/www/html
- /mnt/nextcloud/data:/var/www/html/data
depends_on:
- db
- redis
environment:
- POSTGRES_HOST=db
- POSTGRES_DB=nextcloud
- POSTGRES_USER=nextcloud
- POSTGRES_PASSWORD=secret
- REDIS_HOST=redis
- NEXTCLOUD_ADMIN_USER=admin
- NEXTCLOUD_ADMIN_PASSWORD=admin123
- NEXTCLOUD_TRUSTED_DOMAINS=cloud.herrerosolis.com
- NEXTCLOUD_OVERWRITEHOST=cloud.herrerosolis.com
- NEXTCLOUD_OVERWRITEPROTOCOL=https
db:
image: postgres:15
container_name: nextcloud_db
restart: unless-stopped
volumes:
- /mnt/nextcloud/db:/var/lib/postgresql/data
environment:
- POSTGRES_DB=nextcloud
- POSTGRES_USER=nextcloud
- POSTGRES_PASSWORD=secret
redis:
image: redis:alpine
container_name: nextcloud_redis
restart: unless-stopped
volumes:
- /mnt/nextcloud/redis:/data
caddy:
build:
context: .
dockerfile: Dockerfile.caddy
container_name: nextcloud_caddy
restart: unless-stopped
ports:
- 443:443
volumes:
- /mnt/nextcloud/caddy/Caddyfile:/etc/caddy/Caddyfile
- /mnt/nextcloud/caddy/data:/data
- /mnt/nextcloud/caddy/config:/config
environment:
- CLOUDFLARE_API_TOKEN=${CLOUDFLARE_API_TOKEN}
depends_on:
- nextcloud
networks:
default:
name: nextcloud_net
EOF
echo "📄 Generando Dockerfile.caddy con plugin Cloudflare DNS..."
cat > Dockerfile.caddy <<EOF
FROM caddy:builder AS builder
RUN xcaddy build --with github.com/caddy-dns/cloudflare
FROM caddy:latest
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
EOF
echo "📄 Generando Caddyfile..."
cat > /mnt/nextcloud/caddy/Caddyfile <<EOF
cloud.herrerosolis.com {
reverse_proxy nextcloud:80
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
}
encode gzip
header {
Strict-Transport-Security "max-age=31536000; includeSubDomains; preload"
}
}
EOF
echo "🔐 Añade tu token Cloudflare al archivo .env si no lo has hecho aún:"
if [ ! -f .env ]; then
echo "CLOUDFLARE_API_TOKEN=pon_aqui_tu_token" > .env
echo "✔️ Archivo .env creado. Edita y pon tu token Cloudflare."
else
echo "✔️ Archivo .env ya existe. Asegúrate de que el token sea correcto."
fi
echo "🚀 Levantando contenedores con build personalizado..."
docker compose up -d --build
echo "✅ Todo listo. Accede a https://cloud.herrerosolis.com"
Verify security config[edit]
https://cloud.herrerosolis.com/index.php/settings/admin/overview
Allow big file upload[edit]
php.ini:
upload_max_filesize = 2G
post_max_size = 2G
memory_limit = 1G
Backups[edit]
The important paths to backup are:
/mnt/nextcloud/db(PostgreSQL)/mnt/nextcloud/data(tus archivos)/mnt/nextcloud/nextcloud(archivos de Nextcloud + apps instaladas)/mnt/nextcloud/caddy(configuración SSL + Caddyfile)
Updates[edit]
docker compose pull
docker compose up -d