Compare commits

..

5 Commits

Author SHA1 Message Date
f66e425d35
Add service container for executing cron tasks 2024-04-10 21:37:45 -04:00
27d78a4822
Document new custom nginx image 2024-04-10 19:25:21 -04:00
5ea5533ae8
Update compose to use new custom nginx infrastructure 2024-04-10 19:13:03 -04:00
ad2d6877e5
Add dockerfile for building custom nginx container
Add entrypoint that calls envsubst ahead of starting nginx
2024-04-10 19:13:03 -04:00
0a84c8dd1b
Move nginx config to template file
Replace hardcoded config values with environment variables
2024-04-10 18:49:01 -04:00
5 changed files with 64 additions and 10 deletions

View File

@ -61,6 +61,12 @@ Simply run this command from the root of the cloned repo:
this will take a while.
### Building nginx
This will embed an optimized configuration for serving Nextcloud files and PHP-FPM resources. Run this
command from the root of the cloned repo:
`docker compose build nginx`
### Installing Nextcloud
Run `docker compose up -d`. If something doesn't work try debugging it yourself of open an issue with the php-fpm and nginx logs attached.
@ -82,9 +88,6 @@ Edit `/your/nextcloud/root/nextcloud/config/config.php` and add the following op
),
```
### Editing nginx.conf
You may also have to replace `example.com` with your own domain or multiple domains in the nginx.conf file.
### Enabling system cron (optional)
Nextcloud must perform background tasks. The best way to do that is to use cron. However, on docker this is not easily doable. Here the host will perform the cronjobs required.

View File

@ -3,14 +3,17 @@ services:
nginx:
container_name: nginx-nextcloud
image: nginx:latest
build: ./nginx
ports:
- 80:80
- 443:443
volumes:
- ${NEXTCLOUD_DIR}:/var/www/html
- ${DATA_DIR}:/data
- ./nginx.conf:/etc/nginx/nginx.conf:ro
environment:
- NEXTCLOUD_PHP_FPM_HOST=${NEXTCLOUD_PHP_FPM_HOST}
- NEXTCLOUD_DOMAIN=${NEXTCLOUD_DOMAIN}
- NEXTCLOUD_MAX_UPLOAD_SIZE=${NEXTCLOUD_MAX_UPLOAD_SIZE}
networks:
- nextcloud
depends_on:
@ -20,7 +23,10 @@ services:
php-fpm-nextcloud:
container_name: php-fpm-nextcloud
build: ./php-fpm
build:
context: ./php-fpm
tags:
- localhost/php-fpm-nextcloud:latest
volumes:
- ${NEXTCLOUD_DIR}:/var/www/html
- ${DATA_DIR}:/data
@ -51,6 +57,25 @@ services:
networks:
- nextcloud
cron-nextcloud:
container_name: cron-nextcloud
image: localhost/php-fpm-nextcloud:latest
restart: unless-stopped
command:
- bash
- -c
- "'while true; do php --define apc.enable_cli=1 /var/www/html/cron.php && sleep 300; done'"
networks:
- nextcloud
user: www-data
volumes:
- ${NEXTCLOUD_DIR}:/var/www/html
- ${DATA_DIR}:/data
depends_on:
- php-fpm-nextcloud
- redis-nextcloud
- mariadb-nextcloud
networks:
nextcloud:
driver: bridge

10
nginx/Dockerfile Normal file
View File

@ -0,0 +1,10 @@
FROM docker.io/library/nginx:latest
ENV NEXTCLOUD_DOMAIN=example.com
ENV NEXTCLOUD_PHP_FPM_HOST=php-fpm-nextcloud:9000
ENV NEXTCLOUD_MAX_UPLOAD_SIZE=512M
ADD nginx.conf.template /nginx.conf.template
ADD docker-entrypoint.sh /docker-entrypoint.sh
ENTRYPOINT ["sh", "-c", "/docker-entrypoint.sh"]

16
nginx/docker-entrypoint.sh Executable file
View File

@ -0,0 +1,16 @@
#/usr/bin/env bash
# This implementation is adapted from the solution proposed here:
# https://stackoverflow.com/questions/21866477/nginx-use-environment-variables
# envsubst will take the input and replace all references to environment
# variables with their corresponding value. Because nginx uses the same
# '$' prefix for its internal variables, we should explicitly define the
# variables we want to replace rather than replacing all env vars.
envsubst '
$NEXTCLOUD_PHP_FPM_HOST
$NEXTCLOUD_DOMAIN
$NEXTCLOUD_MAX_UPLOAD_SIZE
' < /nginx.conf.template > /etc/nginx/nginx.conf
exec nginx -g 'daemon off;'

View File

@ -2,7 +2,7 @@ events { worker_connections 1024; }
http {
upstream php-handler {
server php-fpm-nextcloud:9000;
server ${NEXTCLOUD_PHP_FPM_HOST};
#server unix:/run/php/php8.2-fpm.sock;
}
@ -16,7 +16,7 @@ http {
listen 80;
listen [::]:80;
# INFO: Set this to your domain
server_name example.com;
server_name ${NEXTCLOUD_DOMAIN};
# Prevent nginx HTTP Server Detection
server_tokens off;
@ -34,7 +34,7 @@ http {
add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" always;
# set max upload size and increase upload timeout:
client_max_body_size 512M;
client_max_body_size ${NEXTCLOUD_MAX_UPLOAD_SIZE};
client_body_timeout 300s;
fastcgi_buffers 64 4K;