4

I'm trying to run nextcloud docker in a subdir pointing /var/www/nextcloud in a nginx docker.

But no matter what I do, nginx continues to try to serve the /var/www/nextcloud/nextcloud when I access it.

This is the ngix.conf (notice the root /var/www; line)

user www-data;

http {
  upstream backend {
    server nextcloud:9000;
  }
  upstream php-handler {
      server nextcloud:9000;
  }

  server {
      listen 80;

      # Add headers to serve security related headers
      # Before enabling Strict-Transport-Security headers please read into this
      # topic first.
      #add_header Strict-Transport-Security "max-age=15768000;
      # includeSubDomains; preload;";
      add_header X-Content-Type-Options nosniff;
      add_header X-XSS-Protection "1; mode=block";
      add_header X-Robots-Tag none;
      add_header X-Download-Options noopen;
      add_header X-Permitted-Cross-Domain-Policies none;

      # Path to the root of your installation
      root /var/www;

      location = /robots.txt {
          allow all;
          log_not_found off;
          access_log off;
      }

      # The following 2 rules are only needed for the user_webfinger app.
      # Uncomment it if you're planning to use this app.
      # rewrite ^/.well-known/host-meta /nextcloud/public.php?service=host-meta
      # last;
      #rewrite ^/.well-known/host-meta.json
      # /nextcloud/public.php?service=host-meta-json last;

      location = /.well-known/carddav {
        return 301 $scheme://$host/nextcloud/remote.php/dav;
      }
      location = /.well-known/caldav {
        return 301 $scheme://$host/nextcloud/remote.php/dav;
      }

      location /.well-known/acme-challenge { }

      location ^~ /nextcloud {

          # set max upload size
          client_max_body_size 512M;
          fastcgi_buffers 64 4K;

          # Enable gzip but do not remove ETag headers
          gzip on;
          gzip_vary on;
          gzip_comp_level 4;
          gzip_min_length 256;
          gzip_proxied expired no-cache no-store private no_last_modified no_etag auth;
          gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy;

          # Uncomment if your server is build with the ngx_pagespeed module
          # This module is currently not supported.
          #pagespeed off;

          location /nextcloud {
              rewrite ^ /nextcloud/index.php$uri;
          }

And then I have the following in my nginx docker-compose.yml (notice the - /mnt/server/nextcloud:/var/www/nextcloud line in the volumes:

  web:
    image: nginx
    container_name: nginx-webserver
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
      - /mnt/server/nextcloud:/var/www/nextcloud
    external_links:
      - nextcloud
    environment:
      - VIRTUAL_HOST=${DOMAIN}
      - VIRTUAL_NETWORK=nginx-proxy
      - VIRTUAL_PORT=80
      - LETSENCRYPT_HOST=${DOMAIN}
      - LETSENCRYPT_EMAIL=myemail
    networks:
      - proxy-tier
    restart: always

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

And finally my docker-compose.yml for nextcloud (notice the - /mnt/server/nextcloud/:/var/www/html/ line for the volumes):

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

networks:
  proxy-tier:
    external:
      name: nginx-proxy
jbssm
  • 6,861
  • 13
  • 54
  • 81
  • You're talking about using Nginx to proxy another service, right? But you don't seem to be using any `proxy_` directives... – Oliver Charlesworth Aug 21 '17 at 08:07
  • Right, but if I put a `proxy_pass http://backend;` inside the `location` commands I get the exact same result. In any case what is failing right from the beginning is that nginx doesn't honor the `root /var/www` command for some reason I can't understand, it keeps looking at /var/www/nextcloud as the root. – jbssm Aug 21 '17 at 08:12

0 Answers0