This guide outlines how to deploy Nextcloud-FPM using Docker Compose and connect it to a bare metal NGINX reverse proxy running on the host system.

1. Docker Compose Configuration

Create a file named docker-compose.yml:

version: '3.7'
services:
  nextcloud:
    image: nextcloud:fpm
    container_name: nextcloud-app
    restart: always
    volumes:
      - nextcloud_data:/var/www/html
    environment:
      - MYSQL_PASSWORD=your_db_password
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=db
      - REDIS_HOST=redis
    ports:
      - "9000:9000"
  db:
    image: mariadb:10.6
    container_name: nextcloud-db
    restart: always
    environment:
      - MYSQL_ROOT_PASSWORD=your_root_password
      - MYSQL_PASSWORD=your_db_password
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    volumes:
      - db_data:/var/lib/mysql
  redis:
    image: redis:alpine
    container_name: nextcloud-redis
    restart: always
volumes:
  nextcloud_data:
  db_data:

2. NGINX Reverse Proxy Configuration

Create a file at /etc/nginx/sites-available/nextcloud:

server {
    listen 80;
    server_name yourdomain.com;

    root /var/www/nextcloud;
    client_max_body_size 512M;

    location / {
        proxy_pass http://127.0.0.1:9000;
        include fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_param SCRIPT_FILENAME /var/www/nextcloud/index.php;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_index index.php;
    }

    location ~ ^(.+\.php)(.*)$ {
        root /var/www/nextcloud;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $2;
        fastcgi_pass 127.0.0.1:9000;
    }

    location ~* \.(?:jpg|jpeg|gif|bmp|ico|png|css|js|svg|woff|woff2|ttf|eot|otf|ogg|mp4|webm|wav|mp3)$ {
        try_files $uri /index.php$request_uri;
        access_log off;
        expires 30d;
    }
}

Enable the Site and Reload NGINX

sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Need Help With Cloud Development?

Work with our skilled Cloud developers to accelerate your project and boost its performance.

Hire Cloud Developers

Support On Demand!

Related Q&A