I
Immich•3y ago
madkatz

DNS Rewrite Help

Trying to set up a DNS rewrite for when I am on my local network, but keep the domain name so it works remotely. I cannot get the app to login when on my local network. https://photos.mydomain.com properly redirects to my home server, proxied through NPM to Immich and works fine. Remotely, https://photos.mydomain.com/api logins on the app, no issues (other than slow speeds). On my home server, AdGuard Home set to redirect photos.mydomain.com to my NPM IP. In my browser on LAN, I can access photos.mydomain.com and I can see the rewrite happen properly in the AdGuard queries. But when I try to login with the app, it fails. AdGuard processes the rewrite...so not sure where the failure point is. Any thoughts?
118 Replies
jrasm91
jrasm91•3y ago
Are you using the default compose setup? Specifically the nginx proxy running on 2283, and redirecting /api internally to the server?
madkatz
madkatzOP•3y ago
using the default compose setup So NPM is proxied to IP:2283 for everything
jrasm91
jrasm91•3y ago
If you're using everything vanilla like that, it should just be a matter of dns. External => router => npm => immich and Internal => adguard => npm => immich. npm runs on 443, right?
madkatz
madkatzOP•3y ago
Right, but the app fails. In a browser I can do Internal -> Adguard -> NPM -> Immich
jrasm91
jrasm91•3y ago
And get the website, but the login isn't working?
madkatz
madkatzOP•3y ago
Correct NPM is on 443, but there is no way to specify that in the rewrite? Website works, mobile app on android fails
jrasm91
jrasm91•3y ago
What do you mean by rewrite? you mean dns => ip?
madkatz
madkatzOP•3y ago
DNS rewrite in AdGuard - I have it as photos.mydomain.com and then localIPofNPM
jrasm91
jrasm91•3y ago
AdGuard is functioning as a dns server right? So it's like a A record?
madkatz
madkatzOP•3y ago
yup, works for all my other self-hosted apps. I have a wildcard DNS rewrite *.mydomain.com and all my apps are accessible, including Immich in a browser only the app fails for some reason
jrasm91
jrasm91•3y ago
Do you have any other self hosted app with mobile phones?
madkatz
madkatzOP•3y ago
like either the /api doesn't pass through or there is a cert error somewhere
jrasm91
jrasm91•3y ago
Can you open the dev tools in the web and look at the console for errors, and/or the network tab?
madkatz
madkatzOP•3y ago
well the other apps I use (like Nzb360) have options for separate LAN and WAN domain/IPs. SOmething that has been requested for Immich but denied
jrasm91
jrasm91•3y ago
What do you mean by that?
madkatz
madkatzOP•3y ago
GitHub
[Feature]: Second server url for fallback / local ip to external do...
Feature detail It would be nice to automatically switch between uploading from the local network connection when at home to viewing from any location when outside. example: when at home, we connect...
madkatz
madkatzOP•3y ago
Several mobile apps I use that connect to self-hosted software use this fallback method
jrasm91
jrasm91•3y ago
gotcha
madkatz
madkatzOP•3y ago
But I get that Immich doesn't want to, just struggling to troubleshoot this DNS rewrite method
jrasm91
jrasm91•3y ago
You're being forced to solve it with networking instead 😛
madkatz
madkatzOP•3y ago
haha correct how do I open dev tools?
jrasm91
jrasm91•3y ago
F12 or right click inspect element or ctrl + shift + i or ctrl + shift + j
madkatz
madkatzOP•3y ago
got it
jrasm91
jrasm91•3y ago
There should be a network tab do you see any errors in that tab or in the console tab. Might need to do a page refresh
madkatz
madkatzOP•3y ago
Looks okay, but again this is in my browser. The issue I have is the mobile app will not login when my DNS rewrite is enabled
jrasm91
jrasm91•3y ago
Is it only mobile app, I thought you mentioned a problem in the web as well.
madkatz
madkatzOP•3y ago
nope, web works perfectly on LAN with the rewrite
jrasm91
jrasm91•3y ago
Oh, I think I misinterpreted a "Correct" which was referring to something else. Is your phone "pointing at" adguard? Do you see queries for the domain come in when you use the app?
madkatz
madkatzOP•3y ago
yeah - I can see the query in Adguard being rewritten from my phone
jrasm91
jrasm91•3y ago
and it's going to the right ip?
madkatz
madkatzOP•3y ago
oh I think I know the issue
jrasm91
jrasm91•3y ago
It sounds like everything should be working. What's the actual error you are getting?
madkatz
madkatzOP•3y ago
I use Authelia normally but have an auth_Request_off for /api requests but for some reason, the DNS rewrite is not allowing it to bypass Authelia
jrasm91
jrasm91•3y ago
Is this where you have to login with authelia first, and then it redirects you back to immich?
madkatz
madkatzOP•3y ago
correct, which for the browser works fine. Usually for mobile apps I have an exception for /api requests this prevents Authelia from getting in the way
jrasm91
jrasm91•3y ago
And you added one for immich?
madkatz
madkatzOP•3y ago
yes
jrasm91
jrasm91•3y ago
What is the server url you are setting in the mobile app? Does it end with /api?
madkatz
madkatzOP•3y ago
yes so I am not sure why NPM does not see the /api after the DNS rewrite
jrasm91
jrasm91•3y ago
Do you see the whole url in adguard or just the hostname?
madkatz
madkatzOP•3y ago
just the hostname
jrasm91
jrasm91•3y ago
What's the error in the mobile app specifically?
madkatz
madkatzOP•3y ago
"Error logging you in, check server URL, email, and password" Not Authelia actually, I disabled it and same error
jrasm91
jrasm91•3y ago
You have https I'm assuming?
madkatz
madkatzOP•3y ago
mobile app will not work with DNS rewrite yes on the domain I do, with SSL cert
jrasm91
jrasm91•3y ago
It's not self-signed is it?
madkatz
madkatzOP•3y ago
nope, it's through NPM Let's Encrypt
jrasm91
jrasm91•3y ago
should be all good then. Does the mobile app work on mobile data, without being on the local network?
madkatz
madkatzOP•3y ago
yup works perfectly
jrasm91
jrasm91•3y ago
It does? It just doesn't work when you switch to wifi?
madkatz
madkatzOP•3y ago
Correct
jrasm91
jrasm91•3y ago
If the wifi on a different subnet?
madkatz
madkatzOP•3y ago
nope, all same subnet 192.168.1.0/24 if I turn off DNS rewrite - then the app works on my LAN WiFi (but slowly obviously, since it goes out to WAN and back)
jrasm91
jrasm91•3y ago
Can you send your (redacted) DNS rewrite settings? Can you access immich directly by ip from the app?
madkatz
madkatzOP•3y ago
No description
madkatz
madkatzOP•3y ago
and yes, if I put the Immich IP in my app then it works too
jrasm91
jrasm91•3y ago
And that's the ip for npm?
madkatz
madkatzOP•3y ago
yup I feel like it's a security thing? My browser can load my domain using the DNS rewrite, but it makes me accept the unsecure connection since Immich only uses HTTP
jrasm91
jrasm91•3y ago
Wait, I thought you said https + certificate?
madkatz
madkatzOP•3y ago
yes NPM has that with my domain but an internal DNS rewrite shows insecure
jrasm91
jrasm91•3y ago
I know if you use https in the mobile app it requires valid certificates So that could be it. Does the mobile app not go through npm still? Shouldn't the certificate be valid?
madkatz
madkatzOP•3y ago
does a DNS rewrite break the https chain? Since when I have DNS rewrite my browser says my domain is insecure. But when I turn off the rewrite and my domain goes through WAN, then it is secure
jrasm91
jrasm91•3y ago
dns has to do with resolving hostnames to ips, and the ssl part is independent of that, but the hostname on the request needs to match the certificate. I'm not familiar with "Ad Guard rewrites", but I kind of assumed "answer with" means a dns response. If it is actually terminating ssl and proxy a new connection to immich it could be a problem.
madkatz
madkatzOP•3y ago
yeah it certainly shouldn't be proxying any connection. I do wonder though if the IP that is answers with defaults to HTTP over port 80 instead of 443 does that make sense? or should that not matter?
jrasm91
jrasm91•3y ago
So you have dns to ip and separately you have the port of communication and separately you have the protocol.
madkatz
madkatzOP•3y ago
got it
jrasm91
jrasm91•3y ago
dns to ip is immich.domain to 192.168.x.x That seems to be working fine https://immich.domain.tld/api is using https (ssl) on the default port (443)
madkatz
madkatzOP•3y ago
right, works in the browser, but loses SSL when "rewritten"
jrasm91
jrasm91•3y ago
What is the actual certificate error you get? In chrome you can click on the badge thing here and click on certificate to see some details
jrasm91
jrasm91•3y ago
No description
jrasm91
jrasm91•3y ago
Or in the dev tools, there is a security tab
No description
madkatz
madkatzOP•3y ago
So it's a bit interesting and unclear what's happening, let me show you
madkatz
madkatzOP•3y ago
No description
jrasm91
jrasm91•3y ago
And in more information
madkatz
madkatzOP•3y ago
No description
jrasm91
jrasm91•3y ago
What about view certificate And/or open the site in chrome if you have it installed and look at the security tab. That is usually clearer which part of the certificate is causing it to be "insecure".
madkatz
madkatzOP•3y ago
oops will delete that after you look, didnt block my domain haha
jrasm91
jrasm91•3y ago
Yeah, you can delete it So what is the "security exception" that's been added? What about the connection is insecure?
madkatz
madkatzOP•3y ago
No description
madkatz
madkatzOP•3y ago
when I click advanced it says this: This server could not prove that it is photos.mydomain.net; its security certificate is from mydomain.net. This may be caused by a misconfiguration or an attacker intercepting your connection.
jrasm91
jrasm91•3y ago
yeah, open the dev tools and go to the security tab
madkatz
madkatzOP•3y ago
I do have a wildcard cert on the domain
madkatz
madkatzOP•3y ago
No description
jrasm91
jrasm91•3y ago
Well that's it
madkatz
madkatzOP•3y ago
but there is a cert there? and it's Let's Encrypt
jrasm91
jrasm91•3y ago
Can you show me the cert details again (redacted)
madkatz
madkatzOP•3y ago
No description
jrasm91
jrasm91•3y ago
and details
madkatz
madkatzOP•3y ago
No description
madkatz
madkatzOP•3y ago
you have to click on individual items to see the details
jrasm91
jrasm91•3y ago
The certificate error goes away when you turn off adguard though?
madkatz
madkatzOP•3y ago
when I turn off DNS rewrite:
No description
jrasm91
jrasm91•3y ago
It's sending a different certificate This one is issued by E1 oppose to R3 or whatever?
madkatz
madkatzOP•3y ago
oh true, yeah, weird and that's the error on the first one "ERR_CERT_COMMON_NAME_INVALID:
jrasm91
jrasm91•3y ago
soooo where is this certificate coming from one is using quic and one is using tls 1.3 One is issued by R3 and one is issued by E1 Do you have some things turned on in adguard that could be causing this? https filtering?
madkatz
madkatzOP•3y ago
Not that I am aware of, only really use AdGuard to block ads
jrasm91
jrasm91•3y ago
I'd guess the certificate is coming from adguard
jrasm91
jrasm91•3y ago
No description
jrasm91
jrasm91•3y ago
Is there a place for whitelisting sites? Maybe add the immich one there
madkatz
madkatzOP•3y ago
I think that's like the AdGuard browser plugin? separate from the DNS self-hosted server AdGuard Home is just a DNS server
jrasm91
jrasm91•3y ago
Well, something is fishy. You have two certificates issued by different intermediates. One is presumably coming from npm directly and another one must be coming from somewhere else.
madkatz
madkatzOP•3y ago
yeah somehow NPM is issuing a different one when the DNS rewrite occurs
jrasm91
jrasm91•3y ago
Is ad guard the only dns server on your network? How does the web connect to npm when adguard is turned off? Or all queries go to adguard all the time, it's just the rewrite that you turn off?
madkatz
madkatzOP•3y ago
yeah AdGuard is only DNS server (I have two instances running on separate servers for redundancy). My router tells clients the AdGuard IP for DNS queries "turning the rewrite off" is just me deleting it from AdGuard and letting it use the normal DNS resolver
jrasm91
jrasm91•3y ago
Yeah, I'm at a loss here. With it on/off the route to immich is taking two different paths, and tls is terminated two different places. You could maybe try doing a wrong login on the web with the ad guard turned on and then off. In the server logs it should say "wrong login from {ip}" and maybe the ip would tell you what upstream server the request is coming from. Maybe they're different.
madkatz
madkatzOP•3y ago
where can I see the server logs? In Docker for the server container I see websocket connections, but no IPs listed
jrasm91
jrasm91•3y ago
did you do a wrong login attempt on the web?
madkatz
madkatzOP•3y ago
yeah oh i see it [Nest] 1 - 01/20/2023, 6:43:25 AM WARN [AuthService] Failed login attempt for user [email protected] from ip address ::ffff:172.21.0.8 same IP listed regardless of DNS rewrite, so weird oh that's just the IP of the Immich proxy Docker anyways - you've given more than enough time to troubleshooting this. I REALLY appreciate the effort and I learned a few things along the way. Ill keep workign on it slowly as I have time, but for now Ill just have to deal with DNS rewrite off and slow Immich uploads
jrasm91
jrasm91•3y ago
Sounds good. You could try enabling docker logs for the proxy
jrasm91
jrasm91•3y ago
No description
jrasm91
jrasm91•3y ago
If you remove those two lines you should have logs in the immich_proxy container, which should show the original ips
madkatz
madkatzOP•3y ago
kk will try
jrasm91
jrasm91•3y ago
Heading to bed now. Gl!
madkatz
madkatzOP•3y ago
thanks! goodnight! @jrasm91 figured it out! just wanted to let you know, since you helped so much last night
jrasm91
jrasm91•3y ago
Sweet, what was the issue?
madkatz
madkatzOP•3y ago
So when you use Cloudflare for your DNS provider and use their DNS proxy, they use their own SSL cert. That was the external one that was working. When I use the DNS Rewrite, since it was bypassing Cloudflare it was using the SSL cert by NPM. I never realized that I was using Cloudflare's the whole time through their DNS proxy. My NPM SSL cert was not configured properly (only for my domain, not *.domain), so it wasn't a true wildcard cert. I never noticed though since it appeared to be working externally although that was never my cert - was always Cloudflare's. Once I reconfigured NPM's cert to be a true wildcard, everything works now. There are still two different certs depending on external vs internal connection, but both are now valid. Your troubleshooting helped me identify the root issue - noticing that there were different certs. I traced the certs back and that's how I found out about the Cloudflare proxy one vs. my NPM one
jrasm91
jrasm91•3y ago
Awesome! Good find. So now all your services should work locally and remotely, right?
madkatz
madkatzOP•3y ago
correct!

Did you find this page helpful?