Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
    
Are you adding a corresponding hosts entry on that second computer? –  EEAA May 8 '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 8 '12 at 19:42
13  
I think you need to read up on what 127.0.0.1 actually is. –  MDMarra May 8 '12 at 19:52
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 8 '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 8 '12 at 22:20

3 Answers 3

up vote 20 down vote accepted

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.

share|improve this answer
8  
+1 for Yea Bro! That's me! –  dmourati May 8 '12 at 21:58
    
thank you for this I have my answer and understanding and I love the illustration ! –  mcgrailm May 9 '12 at 12:47

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
share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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