How do you tell nextcloud that it's in a sub-directory? Currently each service on my machine is in its own docker instance, and I use Traefik to expose them to different sub-directories on my server:
mydomain/service1
mydomain/service2
all links are "/index.php/*"
all links are "/nextcloud/index.php/*"
if I understood you correctly - you have to adjust your nextcloud configuration:
'overwritewebroot'
Look this:
regards
This is what I was looking for. Is there a way to set this setting via docker, or do I need to modify my version of the image?
Depending on how you run the docker container. If you mount your filesystem in /var/www/html, for example, you don't need to rebuild the container. You can find the config file in the mounted directory.
can you show us some example, I tried everything I could( 'overwritehost' => '', htaccess.RewriteBase' => , etc.), still failed.
I had a similar problem and I have created a fix for this issue (Pull request : #527) that contains the an ENV variable NEXTCOULD_OVERWRITEWEBROOT to help define "subdirectories".
Hope it helps,
Hi,
I am sorry maybe i didn’t get something but in 16.0.3 version , I still have troubles to access to nextcloud with subdirectories as http://myserver/nextcloud/login
anything a do and every variable i use ( like
overwrite.cli.url
'htaccess.RewriteBase' ...)
i get a redirection to http://myserver/login
except if a use the variable
'overwritewebroot' => '/nextcloud’
but in this case i have ERR_TOO_MANY_REDIRECTS error
Is there something i missed ?
Thank you
Best regards
Hi all!
I have the same issue. Migrating to using docker and need nextcloud to use the URL /nextcloud as I have multiple web services all using different folders.
I too get the ERR_TOO_MANY_REDIRECTS error
I've also tried fiddling with the
'htaccess.RewriteBase' => '/nextcloud',
setting as well as RewriteBase / in .htaccess no success. (On some occasions all files were deleted when docker container was started)
PR #527 seems to have morphed into something different so not sure what the fix is for this as I can't get this to work either. What am I missing?
John
I've excatly the same issue and looking for a solution.
Solution, for me, was to have all connections go via proxy when using'overwritewebroot' => '/nextcloud’
If URL is used via web browser (local network) without reverse proxy => ERR_TOO_MANY_REDIRECTS
With proxy (from internet/external), logon screen appears.
Need to do more validation and testing, but looks good so far.
config.php
'overwritewebroot' => '/nextcloud',
'trusted_proxies' =>
array (
0 => 'IP_of_my_proxy',
),
'forwarded_for_headers' =>
array (
0 => 'HTTP_X_FORWARDED_FOR',
),
nginx
location /nextcloud/ {
proxy_headers_hash_max_size 512;
proxy_headers_hash_bucket_size 64;
add_header Front-End-Https on;
proxy_pass http://server/;
}
ymmv...
Update: After moving data and re-using previous DB, Android client re-connected and resumed without any reconfiguration when connecting via proxy. Without going through the proxy, it does not work (at all), lots of errors and timeouts.
I would suspect that 'overwritewebroot' not working when connecting directly is a bug, as per a number of posts here, and hopefully it gets fixed at some point.
I tried everything, not working, by the way I use nextcloud docker image
My configuration is almost the same.
Nextcloud running in a docker container und nginx as webserver / proxy.
The overwritewebroot command didn't work for me either, what is working is the nginx config:
location /nextcloud {
proxy_pass http://localhost:8080;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location = nextcloud/.well-known/carddav {
return 301 $scheme://$host/remote.php/dav;
}
location = nextcloud/.well-known/caldav {
return 301 $scheme://$host/remote.php/dav;
}
Inside the Docker container, I moved the nextcloud files from /var/www/html to /var/www/html/nextcloud
Then I edited the .htaccess file in the /var/www/html/nextloud almost at the bottom line from
RewriteBase / to RewriteBase /nextcloud
Hope that helps, it seems that the command overwritewebroot does not affect the apache config.
The problem with the container restart doesn't affect this config. After a restart there are new files in the /var/www/html folder of a "fresh" nextcloud installation copied.
Here is are some lines of my config.php
<?php
$CONFIG = array (
'htaccess.RewriteBase' => '/nextcloud/',
'memcache.local' => '\\OC\\Memcache\\APCu',
'apps_paths' =>
array (
0 =>
array (
'path' => '/var/www/html/nextcloud/apps',
'url' => '/apps',
'writable' => false,
),
1 =>
array (
'path' => '/var/www/html/nextcloud/custom_apps',
'url' => '/custom_apps',
'writable' => true,
),
),
'instanceid' => '
'passwordsalt' => '',
'secret' => '',
'trusted_domains' =>
array (
0 => 'localhost:PORT',
),
'datadirectory' => '/var/www/html/nextcloud/data',
'dbtype' => 'mysql',
'version' => '16.0.1.1',
'overwrite.cli.url' => 'http://localhost:PORT/nextcloud',
'dbname' => '',
'dbhost' => '',
'dbport' => '',
'dbtableprefix' => 'oc_',
'mysql.utf8mb4' => true,
'dbuser' => '',
'dbpassword' => ,
'installed' => true,
'overwritehost' => 'URL',
'overwriteprotocol' => 'https',
'trusted_proxies' =>
array (
0 => 'https://***.de',
1 => 'https://***.de',
),
'mail_smtpmode' => 'smtp',
'mail_smtpsecure' => 'ssl',
...
'theme' => '',
'loglevel' => 0,
'maintenance' => false,
);
After almost giving up i did a final test and found the following to be working.
i created nextcloud with the following command:
podman run --name nextcloud-my -p 8080:80 -v
vi
add or change "RewriteBase /" to "RewriteBase /your-sub-context"
vi
add 'overwritewebroot' => '/your-sub-context',
cd
ln -s ../html/ your-sub-context
the symlink is important because otherwise somehow the app does not look at the right path. Most likely configurations within the apache would be required, but i didnt want to modify these as i would have to mount those to my host system then. Anyways, hope that this helps for some of you!
@StokeHead Many thanks! It seems htaccess.RewriteBase in config.php does not do its job.
@StokeHead @bakcsa83 thanks to you both but as i documented here i still cannot get Nextcloud served as root but from a subdirectory. it indeed looks like htaccess.RewriteBase does not have an effect but the symlink did not work for me in a non-Docker installation. thanks again.
I found out later that there is a command that updates the .htaccess file:
sudo -u www-data php occ maintenance:update:htaccess (did not try it though)
@waynedpj I can only confirm that the solution described by @StokeHead worked for me.
However, the self-update feature did not work (in brand new image) so I just went back to lxc.
thanks @bakcsa83 however i forgot to mention that i had already tried running the occ maintenance:update:htaccess command as well, still no luck. i had also followed @StokeHead but could not get it working. regardless thanks again.
Same problem as in nextcloud/server#20338.
We need help here, fumbling around inside the container is not the way to go.
_careful bump_
_careless bump_
For anyone who "just wants it to work", i've been able to get it to work with a modified docker image:
FROM nextcloud
RUN apt-get update && apt-get install sudo
RUN echo "sudo -u www-data php occ maintenance:update:htaccess && /usr/local/bin/apache2-foreground">/usr/local/sbin/apache2-foreground && chmod +x /usr/local/sbin/apache2-foreground
CMD ln -srf /var/www/html /var/www/html/nextcloud && /entrypoint.sh apache2-foreground
then just set overwritewebroot and htaccess.RewriteBase to /nextcloud, and http://localhost:<port>/nextcloud should work! (make sure to restart the container)
Now what would be great is a env var to set the RewriteBase property
EDIT: If the above doesn't work, open /var/www/html/.htaccess scroll to line 112, and change RewriteBase to /nextcloud
EDIT2: Or you can just use the linuxserver/nextcloud image, it uses nginx and you can pretty much effortlessly do this (example from their letsencrypt nginx reverse proxy image, linuxserver/letsencrypt, soon to be renamed linuxserver/swag)
# Assuming this container is called "letsencrypt", edit your nextcloud container's config
# located at /config/www/nextcloud/config/config.php and add the following lines before the ");":
# 'trusted_proxies' => ['letsencrypt'],
# 'overwritewebroot' => '/nextcloud',
# 'overwrite.cli.url' => 'https://your-domain.com/nextcloud',
#
# Also don't forget to add your domain name to the trusted domains array. It should look somewhat like this:
# array (
# 0 => '192.168.0.1:444', # This line may look different on your setup, don't modify it.
# 1 => 'your-domain.com',
# ),
# Redirects for DAV clients
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 /nextcloud {
return 301 $scheme://$host/nextcloud/;
}
location ^~ /nextcloud/ {
include /config/nginx/proxy.conf;
resolver 127.0.0.11 valid=30s;
set $upstream_app nextcloud;
set $upstream_port 443;
set $upstream_proto https;
proxy_pass $upstream_proto://$upstream_app:$upstream_port;
rewrite /nextcloud(.*) $1 break;
proxy_max_temp_file_size 2048m;
proxy_set_header Range $http_range;
proxy_set_header If-Range $http_if_range;
proxy_set_header Connection $http_connection;
proxy_redirect off;
proxy_ssl_session_reuse off;
}
(not gonna attach proxy.conf here, just have a look at their image)
Thank you guys!
I could get it working with my setup which also involves a traefik container as reverse proxy. Though I had a minor hickup on the way, namely that the web browser login form and the desktop client's authentication form froze but that can be fixed too as described in the following:
These are the steps on how I got it working:
Pull the image via a docker-compose.yml:
...
service_nextcloud:
image: nextcloud:latest
volumes:
- ./volumes/nc_image/html:/var/www/html
...
Start the containers, then in the nextcloud container the dircetory /var/www/html gets pouplated with code. Within the container I then did:
ln -s /var/www/html/ /var/www/html/intern
chown www-data:root -h /var/www/html/intern
Then open nextcloud in a browser on your domain, register an admin user. Then config files got auto generated of which the next ones to modify are /var/www/html/.htaccess and /var/www/html/config/config.php
modify RewriteBase in /var/www/html/.htaccess where there was the following auto-generated code-block.
This step seems important as without it I get an ERR_TOO_MANY_REDIRECTS error.
#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####
ErrorDocument 403 /intern/
ErrorDocument 404 /intern/
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]
....
RewriteBase /intern # <-- changed from auto generated `RewriteBase /`
....
</IfModule>
Now it would work mostly already, except for the fact that the web login and client authentication form hang. This issue is discussed here: https://github.com/nextcloud/server/issues/19091 and to fix it, add the following to /var/www/html/config/config.php:
...
'overwriteprotocol' => 'https'
...
Now it's all working fine.
My current nextcloud version is 19 and traefik is v2.2
Try this:
https://github.com/nextcloud/nextcloud-snap/wiki/Putting-the-snap-behind-a-reverse-proxy#nginx-optional-custom-path-location-for-reverse-proxy
It worked for me.
It worked for me using the following lines:
docker-compose.yml:
cloud_server:
environment:
- OVERWRITEWEBROOT=/cloud
and config.php:
'htaccess.RewriteBase' => '/cloud',
...and running docker-compose exec -uwww-data cloud_server php occ maintenance:update:htaccess (after updating config.php)
Would be nice to have an env variable for htaccess.RewriteBase to have a clean setup without calling occ manually. Something like OVERWRITEHTACCESSBASE (or something more readable :D)?
PS.: Also @ettingshausen's link was very useful by adding rewrite ^/cloud(.*) $1 break; to my proxy's config 😊
Most helpful comment
After almost giving up i did a final test and found the following to be working.:/var/www/html:Z -e -d docker.io/library/nextcloud:18.0.1-apache/html/.htaccess/html/config/config.php/html/
i created nextcloud with the following command:
podman run --name nextcloud-my -p 8080:80 -v
vi
add or change "RewriteBase /" to "RewriteBase /your-sub-context"
vi
add 'overwritewebroot' => '/your-sub-context',
cd
ln -s ../html/ your-sub-context
the symlink is important because otherwise somehow the app does not look at the right path. Most likely configurations within the apache would be required, but i didnt want to modify these as i would have to mount those to my host system then. Anyways, hope that this helps for some of you!