Nextcloud redirects to local IP when trying to access from domain

Joined
Nov 30, 2023
Messages
3
for anyone still trying to make it work with official app. I solve it by adding
Nextcloud environment variables (one of 2 showed fixed it)
instead of editing config.php. I ataching picture with my working conf.
In case if picture wont work:
Add Nextcloud enviroment in app setup or edit existing app.
Name: OVERWRITEHOST and/or OVERWRITECLIURL
Value: cloud.yourdomain.com View attachment 66052
AMAZING! Thank you!
 

fabianm

Dabbler
Joined
Apr 15, 2023
Messages
11
TY, for the information!

I am preparing a small guide for securing the Nextcloud app using Cloudflare and other methods, and would appreciate it if someone can take a look at it and give me some feedback and criticism to make it easier for others to secure their TrueNAS. I used the information from this thread as well as other resources, but since I am just learning this stuff myself, I hope someone with more experience can spot mistakes and potential problems.

Securing Nextcloud with Cloudflare​


For this solution to work, a free Cloudflare account is needed, as well as a registered domain. The Cloudflare documentation is very well written and covers everything you need to know, setting up a domain and DNS

Setup Cloudflare Tunnel​


Cloudflare Zero Trust is a service for secure access and authentication between users and devices.
cloudflare_tunnel.jpg

It is highly recommended to watch this from Lawrence Systems setting up Cloudflare tunnels for applications. This guide assumes that the applications run as a docker container, but the same approach can be used to secure apps running on TrueNAS Scale in Kubernetes.

In the Cloudflare One dashboard, set a public hostname for accessing Nextcloud, this hostname, in this example it is: nextcloud.example.com
cloudflare_tunnel_hostname.png


The service Type is set to HTTPS and the URL is the local TrueNAS IP + the Nextcloud container port, e.g. 192.168.1.1:9001

In: Additional application Settings > TLS > No TLS Verify = Enabled

cloudflare_tunnel_tls.png


Nextcloud Configuration​


Two environment variables must be set in the Nextcloud application.
overwrite.cli.url and overwritehost

This forum post provided a solution to configuring Nextcloud to for the Cloudflare tunnel reaching the correct port.

In the Nextcloud App, the environment variables are edited as shown below, where `value` is the address.
nextcloud_enviroment_variables.png
 

fabianm

Dabbler
Joined
Apr 15, 2023
Messages
11
for anyone still trying to make it work with official app. I solve it by adding
Nextcloud environment variables (one of 2 showed fixed it)
instead of editing config.php. I ataching picture with my working conf.
In case if picture wont work:
Add Nextcloud enviroment in app setup or edit existing app.
Name: OVERWRITEHOST and/or OVERWRITECLIURL
Value: cloud.yourdomain.com View attachment 66052

@kazaw85 Can you explain why overwritehost and overwritecliurl need to be overwritten? I intend to put this into the TrueNAS documentation and it would be helpful for understanding.
 

victort

Guru
Joined
Dec 31, 2021
Messages
973
@kazaw85 Can you explain why overwritehost and overwritecliurl need to be overwritten? I intend to put this into the TrueNAS documentation and it would be helpful for understanding.
I believe it is because of security. If someone tries to access your server via another domain, or by IP, nextcloud will overwrite and redirect the request to the proper domain. That prevent people from accessing it in devious ways.
 

fabianm

Dabbler
Joined
Apr 15, 2023
Messages
11
I believe it is because of security. If someone tries to access your server via another domain, or by IP, nextcloud will overwrite and redirect the request to the proper domain. That prevent people from accessing it in devious ways.
TY for the reply, found the missing information in the Nextcloud server doc
 

mooneydude

Cadet
Joined
Mar 27, 2024
Messages
1
for anyone still trying to make it work with official app. I solve it by adding
Nextcloud environment variables (one of 2 showed fixed it)
instead of editing config.php. I ataching picture with my working conf.
In case if picture wont work:
Add Nextcloud enviroment in app setup or edit existing app.
Name: OVERWRITEHOST and/or OVERWRITECLIURL
Value: cloud.yourdomain.com View attachment 66052
Does this work for multiple domains or reverse proxy? if so, how do you list more than one ip/domain?
 
Top