Technitium DNS server zone high-availability

Nginx Reverse Proxy with NextCloud using custom or sub-directory URL

Nginx reverse proxy with NextCloud using custom or sub-directory URL.

1. Setup nginx reverse proxy configuration with custom URL or location.

server {
    listen 80;
    listen [::]:80;
   
    server_name your.domain.com;

    location /nextcloud {
        rewrite /nextcloud(/.*)$ $1 break;
        proxy_pass http://your_nextcloud_ip;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
    location /.well-known/carddav {
        return 301 $scheme://$host/nextcloud/remote.php/dav;
    }
    location /.well-known/caldav {
        return 301 $scheme://$host/nextcloud/remote.php/dav;
    }
    
    # fix or suppress unknown webfinger and nodeinfo error
    # https://github.com/nextcloud/documentation/issues/6157
    #rewrite ^/.well-known/webfinger /nextcloud/index.php$uri redirect;
    #rewrite ^/.well-known/nodeinfo /nextcloud/index.php$uri redirect;
    location /.well-known/webfinger {
        return 301 $scheme://$host/nextcloud/index.php$uri;
    }
    location /.well-known/nodeinfo {
        return 301 $scheme://$host/nextcloud/index.php$uri;    
    }
}

2. Apply the same custom URL or location to NextCloud configuration too.

sudo -u www-data php /var/www/nextcloud/occ config:system:set overwritewebroot --value="/nextcloud"

Comments