Go Back   The macosxhints Forums > OS X Help Requests > Networking



Reply
 
Thread Tools Rate Thread Display Modes
Old 07-11-2006, 10:40 PM   #1
skrwl
Prospect
 
Join Date: Dec 2004
Posts: 33
access my apache virtual hosts from another machine

I have a bunch of virtual hosts set up in my /etc/httpd/users/rob.conf for developing various websites, like so:

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
ServerName localhost
DocumentRoot /Library/WebServer/Documents
</VirtualHost>

<VirtualHost 127.0.0.1>
ServerName www.ThisSite.local
DocumentRoot /Users/rob/Sites/ThisSite
</VirtualHost>

<VirtualHost 127.0.0.1>
ServerName www.ThatSite.local
DocumentRoot /Users/rob/Sites/ThatSite
</VirtualHost>

These virtual hosts are working out great on my Mac, which is 192.168.1.102 on my local network.

I've got a PC where I'd like to browser-test these sites too, so I edited the PC's hosts file to include:

192.168.1.102 www.ThisSite.local
192.168.1.102 www.ThatSite.local

But on the PC, I can hit www.ThisSite.local or www.ThatSite.local and it always just serves up the default Apache page: the one from /Library/WebServer/Documents

Anyone know what I'm missing here? Thanks.
skrwl is offline   Reply With Quote
Old 07-11-2006, 10:58 PM   #2
Las_Vegas
League Commissioner
 
Join Date: Sep 2004
Location: Las Vegas
Posts: 5,875
Since your Mac isn't setup or being used as a DNS, this is to be expected. You could edit your Apache home page to redirect according to the calling URL. I expect it should work to simply redirect to the same URL (if it's other than "192.168.1.102") since you've got the local host file setup.
__________________
Las_Vegas

-- Ts'i mahnu uterna ot twan ot geifur hingts uto.
-- Sometimes I wonder… Why is that Frisbee getting Larger? …and then it hits me.
-- Disposable thumbs make me specialer than most animals…
Las_Vegas is offline   Reply With Quote
Old 07-11-2006, 11:21 PM   #3
skrwl
Prospect
 
Join Date: Dec 2004
Posts: 33
Thanks, Las Vegas. I tried using a basic redirect as a test first, before even looking for the calling URL: my new index page in /Library/WebServer/Documents includes

<meta ***********="refresh" content="2;url=http://www.ThisSite.local">

On the OS X box, it works and redirects to ThisSite's DocumentRoot. But when I hit www.ThisSite.local from the PC, it just refreshes itself every 2 seconds.

Did I not follow directions/test properly, or do I need to make my Mac a DNS? Is there another approach I should be taking, like IP/port#-based virtual hosts instead of name-based?
skrwl is offline   Reply With Quote
Old 07-12-2006, 01:20 AM   #4
regulus6633
Major Leaguer
 
Join Date: Apr 2005
Posts: 477
I don't know how to do this with virtual hosts, but I use alias's to access multiple websites on my machine. Here's how:

1. Open your /etc/httpd/httpd.conf file and go to the alias section. Search for the following line to find it...
Alias /icons/ "/usr/share/httpd/icons/"

2. Below that line add an alias for your website. For example...
Alias /testsite/ "/Library/WebServer/TestSite/"

testsite = the fake name you'll use in the url
/Library/WebServer/TestSite/ = the path and name of your website folder

3. Below that you'll need the "Directory" calls. For example use...

<Directory "/Library/WebServer/TestSite">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

4. Repeat steps 2 and 3 for each website you want.

5. The url for your website will be the following and will work from any computer you use.
http://ipaddress/testsite/ <== note you must include the trailing slash in the url

6. Save your changes and restart your webserver.

Good luck.
regulus6633 is offline   Reply With Quote
Old 07-12-2006, 08:53 AM   #5
skrwl
Prospect
 
Join Date: Dec 2004
Posts: 33
Thanks, regulus, but I'm pretty sure if I do it that way, root-relative links on the various sites won't work, no? A lot of sites I've built or inherited use root-relative calls extensively, so changing them all isn't really an option.
skrwl is offline   Reply With Quote
Old 07-12-2006, 09:48 AM   #6
lyndonl
Major Leaguer
 
Join Date: Oct 2003
Location: Johannesburg South Africa
Posts: 259
ok first things first

from the other machine can you see http://192.168.1.102/

Apache might not be listening for connections from anything other than your loopback address ?

also it would be more advisable to use <VirtualHost *:80> and NameVirtualHost *:80

you should be able to run lsof -i as root (sudo should work)

lsof -i | grep http
httpd 158 root 16u IPv4 0x0219dc70 0t0 TCP *:http (LISTEN)
httpd 171 www 16u IPv4 0x0219dc70 0t0 TCP *:http (LISTEN)

if it says ..........TCP 127.0.0.1:http (listen)
then apache is ownly listening on the localhost or loopback address you will not be able to get the site from any other machine on the network

you can also test connectivity by telneting to you ip on port 80 from another machine

if you get somehting like this
telnet 192.168.1.254 80
Trying 192.168.1.254...
Connected to 192.168.1.254.
Escape character is '^]'.

At least you know the server is accepting connections from other hosts

if you get something like this then you know its not
telnet 192.168.1.1 80
Trying 192.168.1.1...
telnet: connect to address 192.168.1.1: Connection refused
telnet: Unable to connect to remote host
lyndonl is offline   Reply With Quote
Old 07-12-2006, 09:56 AM   #7
voldenuit
Hall of Famer
 
Join Date: Sep 2003
Location: Old Europe
Posts: 4,969
Your VirtualHost lines need to point to 192.168.1.102, not loopback.
voldenuit is offline   Reply With Quote
Old 07-12-2006, 10:01 AM   #8
skrwl
Prospect
 
Join Date: Dec 2004
Posts: 33
Quote:
Originally Posted by lyndonl
from the other machine can you see http://192.168.1.102/

Yep, I can. It serves up the default apache page from /Library/WebServer/Documents/.

After discussing this with some colleagues we're thinking that name-based hosts will never work from another machine unless I install OS X server and do some DNS config... Instead, I think I'll try using IP-based virtual domains so each site is on a different port... then I can tell the alternate machine's hosts file to look for

192.168.102:8001 www.ThisSite.local
192.168.102:8002 www.ThatSite.local

I *think* that'll work...

Unless anyone else has some more good advice.

Thanks for all the assistance, y'all!
skrwl is offline   Reply With Quote
Old 07-12-2006, 11:54 AM   #9
lyndonl
Major Leaguer
 
Join Date: Oct 2003
Location: Johannesburg South Africa
Posts: 259
name based config should be fine. i often do what you are trying to do on freebsd running apache and ultimatly apache is apache

provided your ServerName directive is set and the NameVirtualHost and Virtualhost is * or the IP of the Lan card not localhost it should just work provided the /etc/hosts file or relevant hostfile on the other computer matches the IP and the "ServerName" field.

Basically your config as you listed in the first place but with the 192.x.x.x addr rather than the 127.0.0.1 addresses.
lyndonl is offline   Reply With Quote
Old 07-12-2006, 11:59 AM   #10
skrwl
Prospect
 
Join Date: Dec 2004
Posts: 33
Quote:
Originally Posted by lyndonl
Basically your config as you listed in the first place but with the 192.x.x.x addr rather than the 127.0.0.1 addresses.

Aha, THAT makes sense... I bet that'll do it; thanks much for the tip. Will try tonight and post results.
skrwl is offline   Reply With Quote
Old 07-12-2006, 11:59 AM   #11
regulus6633
Major Leaguer
 
Join Date: Apr 2005
Posts: 477
Quote:
Originally Posted by skrwl
Thanks, regulus, but I'm pretty sure if I do it that way, root-relative links on the various sites won't work, no? A lot of sites I've built or inherited use root-relative calls extensively, so changing them all isn't really an option.

I'm not sure why you think apache will work any differently regarding absolute and relative links. If you need to link to files outside of your website's root folder then you can add "FollowSymlinks" to the options under the directory call so that line would look like:

Options Indexes FollowSymlinks MultiViews
regulus6633 is offline   Reply With Quote
Old 07-19-2006, 01:55 PM   #12
skrwl
Prospect
 
Join Date: Dec 2004
Posts: 33
Sorry, forgot to post that voldenuit's and lyndonl's suggestion worked perfectly for what I was trying to accomplish.

regulus6633: Just wasn't as familiar with the approach you suggested and if it'd treat each test site as a unique domain. Sorry if I misunderstood any of your advice and thanks much for contributing it.
skrwl is offline   Reply With Quote
Old 07-19-2006, 02:50 PM   #13
lyndonl
Major Leaguer
 
Join Date: Oct 2003
Location: Johannesburg South Africa
Posts: 259
hey glad to help after all thats what this site is all about
lyndonl is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 10:19 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.