nginx – Client IP is seen as router IP by server when requesting server using public IP/domain by same-network client

I have been struggling with the above question for countless hours and haven’t been able to find an explanation for the behavior either on this site or any other site for that matter. Might be me using the wrong queries though. This is my first question on stack overflow, so please be gentle 😉

The setup I’m using:

I have a server behind my router (which has internal IP and use port forwarding to forward public ports 80 and 443 to my (ubuntu) server. I can access that server either by typing in it’s public IP (say or by going to a domain (say which A records contain the same public IP or by typing in it’s internal IP (say when on the same network. I use NGINX on that server as a reverse proxy to delegate the request to the appropriate (web) applications on the same server. The router is the standard router I got from my internet provider.

I have two clients connecting to that server, client A is on the same network as the server (say, while client B is not on the same network, but anywhere else in the world (say

When I connect with client B (i.e. not on the same network) to my server (either using the public IP or the domain name) and I check the NGINX access logs for the client IP (i.e. $remote_addr) the correct/expected IP address is shown:

Now the part I don’t understand:

When I connect with client A (same network as server) to the server using the internal IP of the server ( the access logs show the correct/expect IP address from the client:
But when I connect from the same client to the server either using the public IP address or the domain name, the NGINX access logs shows the IP address from the router:

Why does this happen? This way I cannot log (and act on) which internal clients connect to the server.