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.

  • 10
    In short, the "people telling you" stuff have left out, or assumed some knowledge. – Criggie Apr 19 '20 at 22:58

(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.

  • Correct answer. In addition, a server program like Apache could get the router to forward requests to it using protocols such as UPnP, if the router is configured to listen to it. It's mostly meant for home usage, not enterprise though. – Jonathan Apr 19 '20 at 11:47
  • 2
    @Jonathan well I live in an house not a Google datacenter so that works for me XD. – lpydawa Apr 19 '20 at 13:47
  • @lpydawa Apache doesn't do UPnP. You will have to manually configure your router to port-forward port 80 (443 for https) to the internal ip-addres of you Apache server. And you will have to tell Apache (in its config files) to respond to your external ip-address, otherwise it will just ignore any http-request. The ip-address the browser thinks your server is located at (your external ip) is in the http request. Apache compares that to the ip-address it knows about in the config to see if it needs to respond to it. (This allows a single server to host multiple sites with different addresses.) – Tonny Apr 20 '20 at 11:26
  • 2
    @Tonny the info you gave is not simplified, it's simply incorrect. Perhaps you're thinking of the Host header? Browsers do not send an IP address in HTTP requests, and no part of the server configuration will deal with the external IP address. – Jeremy Apr 20 '20 at 14:34
  • 3
    @lpydawa Apache does not know or care about your external IP. The address translation performed by your router makes it irrelevant. – Jeremy Apr 20 '20 at 16:33

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: -> -> 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

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.

  • 3
    Putting Apache on a non-standard port (80/8080) would probably require explicit forwarding from the router as well, correct? – Mast Apr 20 '20 at 11:47
  • Port forwarding works in the following way, you can only port forward a PORT or PORT RANGE from your real IP address to the internal IP address. Example: your apache works on a predefined internal IP address and port, you need to select that all information from RealIPAddress:PORT goes to LocalIPAddress:PORT. The problem is that your browser will still be using port 80, and if something wants to connect through SiteName:PORTNot80, you will have to write in the address bar SiteName:PORTNot80. techrepublic.com/blog/diy-it-guy/… – CFCBazar com Apr 21 '20 at 18:59
  • You have to forward RealPAddress:PORT80 to LocalIPAddress:PORTNot80 youtube.com/watch?v=92b-jjBURkw – CFCBazar com Apr 21 '20 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.