Nextcloud Docker redirects to localhost

Nextcloud 15.0.5, Docker 18.09.3, Ubuntu 18.04.2

When I try to do certain things on Nextcloud, such as logging out, it redirects me to localhost:2080’s webroot (which is the port I have redirected out of the container for the internal Apache server) instead of redirecting me to my public web address. I’ve already looked at my config.php’s trusted_domains and overwrite.cli.uri and both of them are set to my public web address. Below you can find my Apache configs (I have Let’s Encrypt enabled on the site).

***/etc/apache2/sites-available/nextcloud.conf***

<VirtualHost *:80>
ServerName <PUBLIC_WEB_ADDRESS>
ProxyPass		"/"	"http://localhost:2080/"
ProxyPassReverse	"/"	"http://localhost:2080/"
RewriteEngine on
RewriteCond %{SERVER_NAME} =<PUBLIC_WEB_ADDRESS>
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

***/etc/apache2/sites-available/nextcloud-le-ssl.conf***

<VirtualHost *:443>
	ServerName <PUBLIC_WEB_ADDRESS>
	ProxyPass		"/"	"http://localhost:2080/"
	ProxyPassReverse	"/"	"http://localhost:2080/"
SSLCertificateFile /etc/letsencrypt/live/<PUBLIC_WEB_ADDRESS>/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/<PUBLIC_WEB_ADDRESS>/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
    <IfModule mod_headers.c>
      Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains"
      Header always set Referrer-Policy "no-referrer"
    </IfModule>
</VirtualHost>
</IfModule>

Is my Apache config wrong? Is there somewhere I’m missing that I have to configure? Thanks for the help!

1 Like

Solved Nextcloud (docker) pointing to localhost

I experienced the same problem and managed to fix it according to the nextcloud documentation after reading a few hours of unanswered posts like this

Have a look at the reverse proxy documentation:
https://docs.nextcloud.com/server/17/admin_manual/configuration_server/reverse_proxy_configuration.html

edit your config.php (at “/var/www/html/config”) and add:

<?php
$CONFIG = array (
  'trusted_proxies'   => ['127.0.0.1'],
  'overwritehost'     => 'yourdomain.tld',
  'overwriteprotocol' => 'https',
  ...
);

add the IP of your proxy to the list of trusted proxies (in my case localhost -> 127.0.0.1) and specify protocol and hosturl to overwrite! Now you should be able to check the url e.g. in your nextclouds settings for Mobile & Desktop

Hope that it can help someone :slight_smile:

2 Likes

The response given by @Friedrich_Greiner is correct. This helped me solve the same problem, where I’ve been wracking my brain trying to fix for the past few days. To be specific, I was using a NGINX reverse proxy pointing towards a docker container with Nextcloud.

My issue was:

  • Can’t log into my Nextcloud account on the desktop/mobile applications

In my case, I created the a custom docker network 172.18.0.0/16, defined in docker-compose.yml, where the nextcloud container was in, therefore my solution was to do the following:

<?php
$CONFIG = array (
  'trusted_proxies'   => ['172.18.0.1'],
  'overwritehost'     => 'yourdomain.tld',
  'overwriteprotocol' => 'https',
  ...
);

172.18.0.1 being the address of the host on which docker was running.

Thank you very much @Friedrich_Greiner!

1 Like