Trick to run docker nextcloud fpm with nginx in a sub directory
The official nextcloud fpm image is great but it does not support mounting to a sub directory. It took me two long days to find this trick, record here for someone might need:
- Compose for initialize. Note: navigate to
https://my.site/nextcloudnow will raise 404:
services:
nginx:
image: nginx:stable-alpine
container_name: nginx1
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/conf.d:/etc/nginx/conf.d
- ./nginx/certs:/etc/ssl/nginx
# - ${DATA_VOLUME}/www:/www
# - ${DATA_VOLUME}/nextcloud:/www/nextcloud
- ${DATA_VOLUME}/www:/var/www/html
- ${DATA_VOLUME}/nextcloud:/var/www/html/nextcloud
restart: unless-stopped
nextcloud:
image: nextcloud:fpm-alpine
container_name: nextcloud1
restart: unless-stopped
# ports:
# - 9000:9000
volumes:
- ${DATA_VOLUME}/nextcloud:/var/www/html
# use the following config instead of above after nextcloud initialized itself:
# - ${DATA_VOLUME}/nextcloud:/var/www/html/nextcloud
- Modify last line of compose file as comments and restart containers. Note: use the modified version BEFORE initialize will cause
cannot delete non-empty directory: nextcloud.
This might be no good solution. On https://stackoverflow.com/a/49861267 i have read that Nextcloud will use rsync on /var/www/html and delete all paths unknown to base installation - so subfolder "nextcloud" and ALL CONTAINING DATA could be silently removed when updating? i have not testet that, but the right solution i would like to use is to use a nginx-proxy for that. Currently i am testing with this example: https://github.com/nextcloud/docker/tree/master/.examples/docker-compose/with-nginx-proxy/postgres/fpm but unfortunatelly had no luck to setup virtual paths.
maybe we both search for a solution at #401 ?
The official nextcloud fpm image is great but it does not support mounting to a sub directory.
Do you actually need Nextcloud to be installed in a subdirectory or merely reachable via a subdirectory? If the latter, just put a reverse proxy in front. If the former, why?