1

I'm trying to get the nextcloud:fpm docker image to run with a nginx docker image plus a neginx-proxy docker image and try to serve several services besides netxcloud (for instace sonarr, etc) from the same nginx image.

In orde to do this I want to configure everything so that when I try: http//my-server.com/nextcloud I'm presented with nexcloud and when I do ``http//my-server.com/sonarr` I go to the sonarr service.

I created a directory like: nginx where I have everything related to nginx. Inside nginx nextcloud` where I configure nexcloud.

In nginx, the docker-compose.yml is:

version: '2'
services:
  proxy:
    image: jwilder/nginx-proxy
    container_name: proxy
    ports:
      - 80:80
      - 443:443
    volumes:
      - /mnt/server/proxy/conf.d:/etc/nginx/conf.d
      - /mnt/server/proxy/vhost.d:/etc/nginx/vhost.d
      - /mnt/server/proxy/html:/usr/share/nginx/html
      - /mnt/server/proxy/certs:/etc/nginx/certs:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
    networks:
      - proxy-tier
    restart: always

  letsencrypt-companion:
    image: alastaircoote/docker-letsencrypt-nginx-proxy-companion
    container_name: letsencrypt-companion
    volumes_from:
      - proxy
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - /mnt/server/proxy/certs:/etc/nginx/certs:rw
    restart: always

  web:
    # image: nginx:alpine
    image: nginx
    container_name: nginx-webserver
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - /mnt/server/nextcloud:/var/www/html/nextcloud/
    external_links:
      - nextcloud
    environment:
      - VIRTUAL_HOST=my-server.com
      - VIRTUAL_NETWORK=nginx-proxy
      - VIRTUAL_PORT=80
      - LETSENCRYPT_HOST=my-server.com
      - LETSENCRYPT_EMAIL=myemail@google.com
    networks:
      - proxy-tier
    restart: always

networks:
  proxy-tier:
    external:
      name: nginx-proxy

and the nginx.conf:

user www-data;

events {
  worker_connections 768;
}

http {
  upstream docker-nextcloud {
      server nextcloud:9000;
  }

  server {
    listen 80;

    location /nextcloud {
      proxy_pass          http://docker-nextcloud;
      proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header    X-Real-IP $remote_addr;
      proxy_set_header    Host $http_host;
      server_name_in_redirect on;
    }

Under the nextcloud directory my docker-compose.yml:

version: '2'
services:
  nextcloud:
    image: nextcloud:fpm
    container_name: nextcloud
    links:
      - db
    volumes:
      - /mnt/server/nextcloud:/var/www/html/nextcloud/
      - /mnt/server/nextcloud/apps:/var/www/html/nextcloud/apps/
      - /mnt/server/nextcloud/config:/var/www/html/nextcloud/config/
      - /mnt/server/nextcloud/data:/var/www/html/nextcloud/data/
    networks:
      - proxy-tier
    restart: always

  db:
    image: postgres
    container_name: db
    volumes:
      - /mnt/server/nextcloud/db:/var/lib/postgresql/
    environment:
      - POSTGRES_DB=nextcloud
      - POSTGRES_USER=nextcloud
      - POSTGRES_PASSWORD=somepassword
    networks:
      - proxy-tier
    restart: always

networks:
  proxy-tier:
    external:
      name: nginx-proxy

This all fails with the message in the nginx docker container log:

2017/08/19 15:05:09 [error] 8#8: *3 recv() failed (104: Connection reset by peer) while reading response header from upstream, client:
172.18.0.6, server: , request: "GET /nextcloud/ HTTP/1.1", upstream: "http://172.18.0.4:9000/nextcloud/", host: "my-server.com"
172.18.0.6 - - [19/Aug/2017:15:05:09 +0000] "GET /nextcloud/ HTTP/1.1" 502 173 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0"
jbssm
  • 6,861
  • 13
  • 54
  • 81
  • So you put an nginx server in front of the nginx proxy image? shouldn't it be only the nginx proxy, or putting an nginx server after the nginx proxy? Did you have a look at the official docker-compose.yml of nextcloud? https://github.com/nextcloud/docker/blob/master/.examples/docker-compose.yml – metanerd Sep 08 '17 at 12:23

2 Answers2

1

The following lines are really dangerous and I recommend to not do any other volume mappings outside of whats documented:

  - /mnt/server/nextcloud:/var/www/html/nextcloud/
  - /mnt/server/nextcloud/apps:/var/www/html/nextcloud/apps/
  - /mnt/server/nextcloud/config:/var/www/html/nextcloud/config/
  - /mnt/server/nextcloud/data:/var/www/html/nextcloud/data/

The reason behind it is that the entry point script does an rsync for all files to /var/www/html and deletes everything they didn't exclude. As result that rsync script tries to delete /var/www/html/nextcloud and all the data bellow it.

Actually how it works internally if the version is different: copy all files from one folder to /var/www/html and delete all but a small set of excluded folders (such as /data). That's why it can't find the required files: they are only copied to /var/www/html and not to /var/www/html/nextcloud where it is expecting them.

I see the following options as a workaround:

  • use the nextcloud:apache image and just use nginx as reverse proxy to rewrite it:

    location /nextcloud/ {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_pass http://nextcloud:80; # nexcloud is the name of the container
        client_max_body_size 1000M;
        rewrite ^/nextcloud(/.*)$ $1 break;
    } 
    
  • use two nginx system (either on a different port or different instance): one that utilizes nextcloud:fpm like the nextcloud would listen to / and one that rewrites /nextcloud (see config in previous point)

Modifying nginx to use fpm and rewrite it looks really, really painful and you need to make sure the various rewrites don't overlap. I tried a few things and it didn't work well, hence I ditched this approach myself. One benefit of using the default is to use the recommended nginx config from Nextcloud that might differ between the versions.

volker
  • 1,805
  • 15
  • 15
0

I am using this set up and it´s working just fine:

NGINX REVERSE PROXY:

version: '3'
services:
  nginx-web:
    image: nginx
    labels:
        com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: "true"
    container_name: ${NGINX_WEB}
    restart: always
    ports:
      - "${IP}:80:80"
      - "${IP}:443:443"
    volumes:
      - ${NGINX_FILES_PATH}/conf.d:/etc/nginx/conf.d
      - ${NGINX_FILES_PATH}/vhost.d:/etc/nginx/vhost.d
      - ${NGINX_FILES_PATH}/html:/usr/share/nginx/html
      - ${NGINX_FILES_PATH}/certs:/etc/nginx/certs:ro
      - ${NGINX_FILES_PATH}/htpasswd:/etc/nginx/htpasswd:ro

  nginx-gen:
    image: jwilder/docker-gen
    command: -notify-sighup ${NGINX_WEB} -watch -wait 5s:30s /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
    container_name: ${DOCKER_GEN}
    restart: always
    volumes:
      - ${NGINX_FILES_PATH}/conf.d:/etc/nginx/conf.d
      - ${NGINX_FILES_PATH}/vhost.d:/etc/nginx/vhost.d
      - ${NGINX_FILES_PATH}/html:/usr/share/nginx/html
      - ${NGINX_FILES_PATH}/certs:/etc/nginx/certs:ro
      - ${NGINX_FILES_PATH}/htpasswd:/etc/nginx/htpasswd:ro
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl:ro

  nginx-letsencrypt:
    image: jrcs/letsencrypt-nginx-proxy-companion
    container_name: ${LETS_ENCRYPT}
    restart: always
    volumes:
      - ${NGINX_FILES_PATH}/conf.d:/etc/nginx/conf.d
      - ${NGINX_FILES_PATH}/vhost.d:/etc/nginx/vhost.d
      - ${NGINX_FILES_PATH}/html:/usr/share/nginx/html
      - ${NGINX_FILES_PATH}/certs:/etc/nginx/certs:rw
      - /var/run/docker.sock:/var/run/docker.sock:ro
    environment:
      NGINX_DOCKER_GEN_CONTAINER: ${DOCKER_GEN}
      NGINX_PROXY_CONTAINER: ${NGINX_WEB}

networks:
  default:
    external:
      name: ${NETWORK}

And this set up for the Nextcloud container:

version: '3'

services:
   cloud-db:
     container_name: ${DB_CONTAINER_NAME}
     image: mariadb:latest
     restart: unless-stopped
     volumes:
        - ${LOCAL_DB_DIR}:/var/lib/mysql
     environment:
       MYSQL_DATABASE: ${MYSQL_DATABASE}
       MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
       MYSQL_USER: ${MYSQL_USER}
       MYSQL_PASSWORD: ${MYSQL_PASSWORD}

   cloud-app:
     depends_on:
       - cloud-db
     container_name: ${APP_CONTAINER_NAME}
     image: nextcloud:latest
     restart: unless-stopped
     volumes:
       - ${LOCAL_DATA_DIR}:/var/www/html
       - ${LOCAL_CONF_DIR}:/var/www/html/config
       - ${LOCAL_APPS_DIR}:/var/www/html/apps
     environment:
       NEXTCLOUD_ADMIN_USER: ${NEXTCLOUD_ADMIN_USER}
       NEXTCLOUD_ADMIN_PASSWORD: ${NEXTCLOUD_ADMIN_PASSWORD}
       NEXTCLOUD_DATA_DIR: ${NEXTCLOUD_DATA_DIR}
       NEXTCLOUD_TABLE_PREFIX: ${NEXTCLOUD_TABLE_PREFIX}
       VIRTUAL_HOST: ${VIRTUAL_HOST}
       LETSENCRYPT_HOST: ${LETSENCRYPT_HOST}
       LETSENCRYPT_EMAIL: ${LETSENCRYPT_EMAIL}
       MYSQL_DATABASE: ${MYSQL_DATABASE}
       MYSQL_USER: ${MYSQL_USER}
       MYSQL_PASSWORD: ${MYSQL_PASSWORD}
       MYSQL_HOST: ${MYSQL_HOST}

networks:
    default:
       external:
         name: ${NETWORK}

All raised from here:

  1. Docker-Compose-LetsEncrypt-Nginx-Proxy-Companion

  2. Docker-Nextcloud-LetsEncrypt

EDIT:

As you mentioned FPM image you must add the following environment opions for the Nextcloud container:

environment:
  [..]
  VIRTUAL_ROOT: /var/www/html
  VIRTUAL_PROTO: fastcgi

Or you could follow the Nextcloud example:

https://github.com/nextcloud/docker/tree/master/.examples/docker-compose/with-nginx-proxy/mariadb/fpm

Evis
  • 571
  • 8
  • 22