0

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?

Ben Pilbrow
  • 11,995
  • 5
  • 35
  • 57

5 Answers5

2

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.

Cesar
  • 121
  • 2
2

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}/

Chris Nava
  • 1,147
  • 1
  • 7
  • 9
1

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.

0

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.

Stephen C
  • 541
  • 4
  • 18
0

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.

daalbert
  • 101
  • 1