title: Using Nextcloud inside a nginx/nxgin-proxy container togheter with other services
body: <p>I'm trying to get the <code>nextcloud:fpm</code> docker image to run with a <code>nginx</code> docker image plus a <code>neginx-proxy</code> docker image and try to serve several services besides netxcloud (for instace sonarr, etc) from the same <code>nginx</code> image.</p>
  
  <p>In orde to do this I want to configure everything so that when I try: <code>http//my-server.com/nextcloud</code> I'm presented with nexcloud and when I do ``http//my-server.com/sonarr` I go to the sonarr service.</p>
  
  <p>I created a directory like:
  <code>nginx</code> where I have everything related to nginx.
  Inside <code>nginx</code> nextcloud` where I configure nexcloud.</p>
  
  <p>In <code>nginx</code>, the <code>docker-compose.yml</code> is:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>and the <code>nginx.conf</code>:</p>
  
  <pre><code>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;
      }
  </code></pre>
  
  <p>Under the <code>nextcloud</code> directory my <code>docker-compose.yml</code>:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>This all fails with the message in the <code>nginx</code> docker container log:</p>
  
  <pre><code>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"
  </code></pre>