Pages

Monday, April 10, 2023

NextCloud Setup with Docker

One of the most commonly used self-hosted alternatives for cloud storages. Now it's easy to deploy with dockers. Following docker file and Nginx configuration can be used to deploy the nextcloud application behind the Nginx proxy server with SSL termination. 
we can bring up and bring down the containers with the following commands

docket-compose up -f
docker-compose down

===========

version: '2'
#volumes:
#  nextcloud: /root/nextcloud/ncdata
#  db: /root/nextcloud/mysql
services:
  db:
    image: mariadb:10.5
    restart: always
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - /root/nextcloud/mysql:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=XXXXXXXXX
      - MYSQL_PASSWORD=XXXXXXXX
      - MYSQL_DATABASE=XXXXXXXX
      - MYSQL_USER=XXXXXXXX
  app:
    image: nextcloud
    restart: always
    links:
      - db
    volumes:
      - /root/nextcloud/ncdata:/var/www/html
    environment:
      - MYSQL_PASSWORD=XXXXXXXX
      - MYSQL_DATABASE=XXXXXXXX
      - MYSQL_USER=XXXXXXXX
      - MYSQL_HOST=XXXXXXXX
      - NEXTCLOUD_TRUSTED_DOMAINS=abc.xyz.aa
      - OVERWRITEHOST=abc.xyz.aa:XXXX
      - OVERWRITEPROTOCOL=https
        
  web:
       image: nginx
       restart: always
       ports:
         - 8082:8080
       links:
         - app
       volumes:
         - /root/nextcloud/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
         - /root/nextcloud/cert:/etc/cert
===========
Nginx Configuration file
===========

server {
  listen 80;
  server_name abc.xyz.aa;
  return 301 https://$server_name:8080$request_uri;
  add_header X-Content-Type-Options              "nosniff";
}
server {
  listen 8080 ssl;
  server_name abc.xyz.aa;
  ssl_certificate /etc/cert/abc.xyz.aa.crt;
  ssl_certificate_key /etc/cert/abc.xyz.aa.key;
  ssl_prefer_server_ciphers on;
  location / {
  proxy_pass http://app;
        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;
 }

===========




No comments:

Post a Comment