How does Apache know my external IP when I am on a LAN on a router that performs NAT?
(Assuming the Apache server is not on a public IP) Apache does NOT know your public IP. The router would need to forward requests on to it and rewrite the destination.
The Apache IP has to be set in the apache config files. When information comes to your real IP addres, this information is re-routed to an internal IP addres and/ or port.
Example:
140.90.15.200
->192.168.1.100:80
-> Apache listens for information on this local IP address.
By default apache listens to some IP address and port 80.
You can use Apache with localhost, which means that you are using IP address 127.0.0.1:80
.
You can configure Apache to listen to any IP and any port, but the default ones are already set in your config files.
Also your web browser by default uses port 80.
Here you can read more.