-3

I'm trying to setup a a virtual host on a machine in my office I've added

127.0.0.1 urs.local

to the hosts file,

and added this to config

NameVirtualHost 127.0.0.1:80

<VirtualHost 127.0.0.1:80>
ServerName localhost 
</VirtualHost> 

<VirtualHost 127.0.0.1:80>
DocumentRoot "/Applications/MAMP/htdocs" 
ServerName urs.local
</VirtualHost>

On that same machine I put urs.local in the browser address bar, and it works.

But, then I go to another computer on the same network, behind the same firewall, and I get "problem loading page."

I think I am missing something somewhere.

Skyhawk
  • 14,149
  • 3
  • 52
  • 95
mcgrailm
  • 204
  • 2
  • 14
  • Are you adding a corresponding hosts entry on that second computer? – EEAA May 08 '12 at 19:41
  • no I want others on the network to see the site but I don't want to do that on all the computers. so right now if i type the ip i see the main site but not the second – mcgrailm May 08 '12 at 19:42
  • 13
    I think you need to read up on what 127.0.0.1 actually is. – MDMarra May 08 '12 at 19:52
  • and Yes I do need to read up on that ! – mcgrailm May 08 '12 at 20:05
  • 5
    @mcgrailm I think that you've probably received a few downvotes because SF is for *professional* systems administrators. The concept of the loopback adapter is fundamental and many feel that any professional systems administrator should know how it works. – MDMarra May 08 '12 at 21:39
  • 1
    I'm not one of the downvoters but I suspect you got those downvotes because as professionals in our fields we should all know this kind of elementary stuff. This really is kindergarten level knowledge. – John Gardeniers May 08 '12 at 22:20
  • @mcgrailm There's a bit of a grey area. Perhaps you should ask this on [meta]. It's been brought up before, but I'm not sure what the outcome was. – MDMarra May 09 '12 at 12:49

3 Answers3

21

I don't think that this has really been properly described here, so here it goes.

127.0.0.1 is a loopback address. It exists on all modern computer systems. Any traffic sent out of an interface with a destination of 127.0.0.1 is immediately received on the loopback interface of the same machine. That traffic never reaches the network.

Since you are listening only on the loopback interface, then the only machine that can ever get to your site is the one hosting the site. When other computers try and connect to 127.0.0.1, they are trying to connect to themselves. You see where the problem is now, I take it?


The concept is probably best illustrated with this drawing:

Awesome Point Diagram


To solve your actual problem, you need to do two things.

  1. Listen on an address that other computers can contact. You have an normal IP of some sort. Use that instead of the 127.0.0.1.
  2. If you must use a named virtualhost (not required), then you will either need to add an entry in the hosts file of every computer contacting your machine, or you will need to add a DNS entry in your local DNS server(s) for urs.local with an IP that is reachable. If you need to do this to more than one or two machines, use DNS. It's the right way™

tl;dr 127.0.0.1 is on an interface whose traffic never leaves the machine that it is connected to. It exists on every modern implementation of the TCP/IP stack. Telling other machines to connect to 127.0.0.1 is going to have them trying to connect to themselves, not your machine.

MDMarra
  • 100,183
  • 32
  • 195
  • 326
4

What URL exactly are you using on the other machines? 127.0.0.1 is localhost. This will never ever be accessible from remote machines, it only points to the local machine. So in order to access your Site on this server from other computers you have to do two things:

  1. Modify the vhost to not listen on 127.0.0.1 only
  2. Chose a server name that is not "localhost" (eg the hostname)
  3. Point the browsers of the remote machines to this server name
leepfrog
  • 488
  • 2
  • 9
3

Yup - That'll have problems for a number of reasons:

1) 127.0.0.x is essentially referring to the system itself. So even if you did update the host files manually on other systems, they wouldn't find their way to the server you want.

2) 127.0.0.x isn't listening for external connections.

I agree that your virtual hosts need to listen on a network accessible IP. Once that's done, you can likely leverage DNS to refer the workstations to the appropriate location.

Mike B
  • 11,570
  • 42
  • 106
  • 165