Ubuntu – Setting up apache2 webserver — differences between behaviour within the intranet and outside


I am new to apache2. I have an ubuntu 12.04.4 LTS machine in my home, and just installed apache2 on it. I wanted to set up a webserver running on a port other than port 80 (my router uses port 80). Here's what I did:

  1. Changed some lines at the beginning of /etc/apache2/ports.conf from

    NameVirtualHost *:80
    Listen 80


    NameVirtualHost *:8041
    Listen 8041
  2. Changed the first line of /etc/apache2/sites-available/default from

    <VirtualHost *:80>


    <VirtualHost *:8041>
  3. Restarted apache2

My ubuntu machine has local IP address, and from any computer on my home intranet if I point a web browser to then I get the standard apache2 "It works!" web page. I also set up my router to port forward any incoming TCP
packets on port 8041 to the ubuntu machine (still on port 8041).

Let's say my ISP has given me the IP address 123.456.78.90. If I am outside my intranet and I point a web browser to http://123.456.78.90:8041 then again it works.

However, within my intranet (on the ubuntu machine itself or on other machines on the intranet), when I point a web browser to http://123.456.78.90:8041 I get an "unable to connect" error.

Where do I go from here? I am now unclear about whether this is an issue with my apache set-up or my router. I have now unfortunately realised though that it is probably not a question about Ubuntu :-/

Best Answer

The issue above is actually expected behaviour. I need to upgrade my router to one that supports "loopback NAT" a.k.a. "hairpin nat". See here for example.

Related Question