Deployment Overview of Nextcloud on Server¶
Prerequisites and Basic Requirements¶
The deployment requires a server with the following configurations and privileges:
- Operating System: Linux distribution compatible with Docker and Docker Compose.
- Privileges: Root access or
sudoprivileges are required to manage Docker containers, firewall rules, and file permissions. - Domain: A valid domain name (
final_domain) must be configured and pointing to the server's IP address. - Ports: The following TCP ports must be open and accessible:
- Port 80 (HTTP)
- Port 443 (HTTPS)
- Port 22 (SSH) (if using UFW firewall)
File and Directory Structure¶
The application and its configuration files are organized in the following directories:
/opt/nextcloud/: Contains the Docker Compose configuration, PHP configuration files, and initialization scripts.compose.yml: Docker Compose definition for the application stack.set_configuration.sh: Script to initialize Nextcloud and install the OnlyOffice app.www.conf,fpm.conf,php.ini: PHP-FPM and PHP configuration files./opt/nginx/: Contains Nginx configuration files.nginx.conf: Main Nginx configuration.nginx-certbot.env: Environment variables for the Certbot container.user_conf.d/: Directory for domain-specific Nginx server blocks (e.g.,{{ final_domain }}.conf).- Data Storage:
/var/www/html: Mount point for Nextcloud data (either a Docker volume or a host directory defined bynextcloud_data_path).- Docker Volumes:
app_data,db_data,document_data,document_log,nginx_secrets.
Application Installation Process¶
The application is deployed using Docker Compose, which orchestrates the following services:
- Nextcloud: Version
nextcloud:fpmrunning as theapp-servercontainer. - Database: PostgreSQL (
postgres:alpine) for data storage. - Cache: Redis (
redis:alpine) for session and cache management. - Document Server: OnlyOffice (
onlyoffice/documentserver:latest) for document editing. - Web Server: Nginx with Certbot (
jonasal/nginx-certbot:latest) for reverse proxying and SSL management.
The deployment process involves:
- Creating necessary directories and Docker volumes.
- Generating the
compose.ymlfile with environment variables for database credentials and domain settings. - Starting the containers using
docker compose up -din the/opt/nextclouddirectory. - Obtaining an SSL certificate via Certbot for the specified domain.
- Executing the
set_configuration.shscript to initialize the Nextcloud instance and configure the OnlyOffice integration.
Access Rights and Security¶
Firewall rules are configured to allow traffic on specific ports depending on the firewall service in use:
- Firewalld:
- Port 80/tcp (enabled, zone: public)
- Port 443/tcp (enabled, zone: public)
- UFW:
- Port 80/tcp (enabled)
- Port 443/tcp (enabled)
- Port 22/tcp (enabled)
Security headers are enforced by the Nginx configuration, including:
Strict-Transport-SecurityX-Frame-OptionsX-Content-Type-OptionsX-XSS-ProtectionX-Robots-TagX-Download-OptionsX-Permitted-Cross-Domain-Policies
Access to sensitive directories such as /build, /tests, /config, /lib, /3rdparty, /templates, and /data is denied via Nginx location blocks.
Databases¶
The application uses a PostgreSQL database with the following settings:
- Image:
postgres:alpine - Database Name:
nextcloud - User:
nextcloud - Password: Defined by the
nextcloud_admin_pwdvariable. - Storage: Data is persisted in the
db_dataDocker volume mounted at/var/lib/postgresql/data. - Connection: The Nextcloud container connects to the database using the hostname
dbon port5432.
Docker Containers and Their Deployment¶
The deployment utilizes Docker Compose to manage the following containers:
- db: PostgreSQL database container.
- redis: Redis cache container.
- app-server: Nextcloud application container.
- onlyoffice-document-server: OnlyOffice document editing container.
- nginx-certbot: Nginx reverse proxy and SSL certificate management container.
Docker volumes are created to ensure data persistence:
app_data: Stores Nextcloud application data (used ifnextcloud_data_pathis not defined).db_data: Stores PostgreSQL data.document_data: Stores OnlyOffice data.document_log: Stores OnlyOffice logs.nginx_secrets: Stores Let's Encrypt SSL certificates.
The containers are started with the command:
executed from the/opt/nextcloud directory. Proxy Servers¶
Nginx is configured as a reverse proxy using the jonasal/nginx-certbot image. It handles:
- SSL Termination: Certificates are obtained and managed by Certbot for the domain
{{ final_domain }}. - HTTP to HTTPS Redirect: Port 80 traffic is redirected to HTTPS (port 443).
- OnlyOffice Proxy: Requests to
/ds-vpath/are proxied to theonlyoffice-document-servercontainer. - Configuration Files:
- Main configuration:
/opt/nginx/nginx.conf - Domain-specific configuration:
/opt/nginx/user_conf.d/{{ final_domain }}.conf - Environment variables:
/opt/nginx/nginx-certbot.env
The Nginx container exposes ports 80 and 443 to the host.
Permission Settings¶
File and directory permissions are set as follows:
/opt/nextcloud: Ownerroot, Grouproot, Mode0640./opt/nginx: Ownerroot, Grouproot, Mode0640./opt/nginx/user_conf.d: Ownerroot, Grouproot, Mode0640.- Configuration files (
compose.yml,set_configuration.sh,nginx.conf, etc.): Ownerroot, Grouproot, Mode0644or0755for executable scripts. - Nextcloud data directory (
nextcloud_data_pathorapp_datavolume): Ownerroot, Grouproot, Mode0755.
Inside the containers, the Nextcloud application runs as the www-data user.
Starting, Stopping, and Updating¶
The application stack is managed via Docker Compose. The following commands are used:
- Start:
- Stop:
- Restart:
- Update: To update the application, pull the latest images and restart the containers:
Post-deployment maintenance tasks are executed via Docker exec commands: