|
|
#1 |
|
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. |
|
|
|
|
|
#2 |
|
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… |
|
|
|
|
|
#3 |
|
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? |
|
|
|
|
|
#4 |
|
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. |
|
|
|
|
|
#5 |
|
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.
|
|
|
|
|
|
#6 |
|
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
__________________
Damn I love www.macosxhints.com my how-to site related to Apple Unix and Cisco My photography site |
|
|
|
|
|
#7 |
|
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.
|
|
|
|
|
|
#8 | |||||||||||||||||||||||
|
Prospect
Join Date: Dec 2004
Posts: 33
|
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! |
|||||||||||||||||||||||
|
|
|
|
|
#9 |
|
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.
__________________
Damn I love www.macosxhints.com my how-to site related to Apple Unix and Cisco My photography site |
|
|
|
|
|
#10 | |||||||||||||||||||||||
|
Prospect
Join Date: Dec 2004
Posts: 33
|
Aha, THAT makes sense... I bet that'll do it; thanks much for the tip. Will try tonight and post results. |
|||||||||||||||||||||||
|
|
|
|
|
#11 | |||||||||||||||||||||||
|
Major Leaguer
Join Date: Apr 2005
Posts: 477
|
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 |
|||||||||||||||||||||||
|
|
|
|
|
#12 |
|
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. |
|
|
|
|
|
#13 |
|
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
__________________
Damn I love www.macosxhints.com my how-to site related to Apple Unix and Cisco My photography site |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|