Nextcloud + PostgreSQL + Redis + Nginx Stack
Self-hosted Nextcloud Docker Compose stack with PostgreSQL database, Redis caching, and Nginx reverse proxy for collaborative file hosting.
yaml
docker-compose.yml
services:
postgres:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- postgres_data:/var/lib/postgresql/data
redis:
image: redis:7-alpine
restart: unless-stopped
command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD}
volumes:
- redis_data:/data
nextcloud:
image: nextcloud:31-apache
restart: unless-stopped
depends_on:
- postgres
- redis
environment:
POSTGRES_HOST: postgres
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
REDIS_HOST: redis
REDIS_HOST_PASSWORD: ${REDIS_PASSWORD}
volumes:
- nextcloud_data:/var/www/html
nginx:
image: nginx:1-alpine
restart: unless-stopped
depends_on:
- nextcloud
command:
- /bin/sh
- "-c"
- |
cat <<'EOF' >/etc/nginx/conf.d/default.conf
server {
listen 80;
client_max_body_size 10g;
location / {
proxy_pass http://nextcloud:80;
proxy_set_header Host $$host;
proxy_set_header X-Real-IP $$remote_addr;
proxy_set_header X-Forwarded-For $$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $$scheme;
}
}
EOF
exec nginx -g 'daemon off;'
ports:
- ${NEXTCLOUD_HTTP_PORT}:80
volumes:
postgres_data:
redis_data:
nextcloud_data:
.ENV
.env example
POSTGRES_USER=nextcloud
POSTGRES_PASSWORD=changeme123
POSTGRES_DB=nextcloud
REDIS_PASSWORD=changeme123
NEXTCLOUD_HTTP_PORT=8080
deployment
Quick Start
- Create a working directory named after the service.
- Copy the compose file and generated `.env` into that directory.
- Review the variables and replace placeholders with real values.
- Run `docker compose up -d`.
mkdir nextcloud-postgresql-redis-nginx-stack
cd nextcloud-postgresql-redis-nginx-stack
# create docker-compose.yml
# create .env
docker compose up -d