How does Apache know my external IP when I am on a LAN on a router that performs NAT?

So, I have setup an Apache server, and people tell me that I need to specify Listen :80 or put a virtual host in httpd.conf so that Apache allows traffic from my public IP.

My question is, how does it know my public IP? Apache is in my LAN within 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.

Additional information(20% relevance): A little bit about port pitfalls from the many years of experience repository. Different ports are accepted and treated by the OS and programs in different ways. For example a certain range of ports are accepted to be used by viruses and are blocked by the anti virus and/or operating system. If you use port 8080, it might be ok, but its good to test a range of ports in order to make sure that the problem does not come from that. Try 8080, 8081, then try with a big difference 9090, 9091.