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

I have apache and what not running on my local machine (mac), there also another mac on the local network. How does this other machine access my localhost?

For example I have a local website at example.local.net in my vhost. How can another computer on the network navigate to this site?

share|improve this question

migrated from stackoverflow.com May 2 '10 at 4:08

This question came from our site for professional and enthusiast programmers.

    
What are you trying to access with ? Can you explain further ? –  Romain Hippeau May 2 '10 at 0:30
    
This question probably belongs on ServerFault or SuperUser –  Mitch Dempsey May 2 '10 at 3:53
1  
@Mitch Dempsey: "Do not move junk".... –  pauska Jul 29 '11 at 19:01

5 Answers 5

You have to edit /etc/hosts on the other mac and add a line like this:

192.168.x.x example.local.net

192.168.x.x it's you LAN ip. You can retrieve it by using ifconfig command in the Terminal.

share|improve this answer

Since they are both Macs and therefore presumably have bonjour running, you may be able to use the machine's hostname directly without any further setup. Try http://{the other machine's hostname}/

share|improve this answer

You should be able to access it via your local IP address. i.e. If you're current navigating to localhost on the Server Mac to retrieve pages from the Server Mac then you instead should be navigating to 192.168.XXX.YYY on the Client Mac to retrieve pages from the server mac. You can find out your local IP address by running ifconfig in a Terminal.

share|improve this answer
    
The IP address will probably not work because he configured a vhost. –  Raffael Luthiger Jul 29 '11 at 22:09

If you are asking if you can set things up so that one machine can talk to another machine's loopback IP (e.g. 127.0.0.1) then the answer is that it cannot be done directly, and it is probably a bad idea.

share|improve this answer

This is assuming the local Apache instance is only listening on localhost, eg 127.0.0.1, otherwise just access it using the machine's IP on the network.

You can use a SSH tunnel.

You can use the -L [bind_address:]port:host:hostport paramater to creat tunnels. See: man ssh

Lets say your local mac has the ip address of 192.168.1.10 and the other mac has the ip address of 192.168.1.11 and the local Apache instance is running on port 80 you could use something along the lines of: ssh -L 10080:127.0.0.1:80 user@192.168.1.10 from the other mac.

This can get confusing but essentially 10080 represents a port created on the other mac (this is can be any free port number, need to be admin to be a lower port number), and 127.0.0.1:80 represents what will be forwarded to the other mac from 192.168.1.10's perspective.

To browse the website hosted on your mac, from the other mac, navigate to http://127.0.0.1:10080.

Please let me know if you need any additional clarification.

share|improve this answer

Your Answer

 
discard

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