Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Virtual Hosts - Apache retard looking for info

Virtual Hosts - Apache retard looking for info
Thread Tools
Mac Elite
Join Date: Jan 2001
Location: L.A., CA
Status: Offline
Reply With Quote
Apr 18, 2003, 02:10 AM
 
OK. I'll say right off the bat that I am completely idiotic when it comes to servering, admin, and especially Apache stuff. I am, however, pretty enthusiastic about serving up a tiny web site, as a hobby mostly.

My next step will be to see if I can get virtual hosting setup correctly (just name based.) I have a decent idea of what I'm looking at. But I was hoping to see if there was anything I should know before proceeding. Any common pitfalls? Anything odd specific to virtual hosting via OS X.2?

~ t h a n x i n a d v a n c e ~
     
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Apr 19, 2003, 12:35 PM
 
MacOS X uses standard Apache, with the exception of how configuration files are set up, so it's pretty much the same as any other Apache installation (and therefore any Apache book can give you pointers).

As regards the configuration file setup, it is best not to edit http.conf directly under MacOS X. Notice the last line of Apple's http.conf file:

   Include /private/etc/httpd/users

That's intended to load http.conf customizations for individual users on your Mac. What it does, effectively, is append every file in the directory /private/etc/httpd/users/, in alphabetical order, to your /etc/httpd/httpd.conf file. So if you place a file containing only the customizations you would otherwise make to /etc/httpd/httpd.conf in the directory /private/etc/httpd/users/, your customizations will always be in effect without ever editing your /etc/httpd/httpd.conf file. Slick, eh? This also saves you from having to re-edit this file if Apple should change it during a system update (folks here on this list have been complaining about this recently, and it is so easily avoided!)

Important safety tip: Every file in /private/etc/httpd/users/ is appended to your /etc/httpd/httpd.conf file, even files with suffixes like ".bak", so keep your backup files in another directory, else they are likely to override the changes you're making in your primary file (e.g. my.httpd.conf.bak would load after my.httpd.conf, which might undo the edits you've made and send you off chasing your tail for hours while trying to figure out why the changes you're making don't seem to work properly -- of course i was never caught by this snare! ).

At any rate, what i would recommend is that you leverage off this feature by creating a virtual.conf file (or whatever name of your choosing) in /private/etc/httpd/users/ for your virtual host definitions. Just to get you started, it might look something like this:
Code:
NameVirtualHost * # A bogus host; acts as default catch-all to # any request to our IP address which is not # otherwise defined below <VirtualHost *> ServerName catch-all.domain DocumentRoot /Users/myname/Sites/undefined </VirtualHost> # Virtual host #1; answer to all machine names. # Also answer to bogus domain name of "gold" # (which we might need in certain circumstances # to test our server to get past a DNS router.) <VirtualHost *> ServerName www.domain1.com ServerAlias domain1.com *.domain1.com ServerAlias gold *.gold DocumentRoot /Users/myname/Sites/gold ErrorDocument 404 /404/404.html </VirtualHost> # Virtual host #2 # Answer to a special machine name (foo). <VirtualHost *> ServerName foo.domain2.net ServerAlias foo.domain2.net ServerAlias foo.silver DocumentRoot /Users/myname/Sites/foo </VirtualHost> # Virtual host #2 # Answer to all other machine names. <VirtualHost *> ServerName www.domain2.net ServerAlias domain2.net *.domain2.net ServerAlias silver *.silver DocumentRoot /Users/myname/Sites/silver </VirtualHost> # Default for all hosts: AddDefaultCharset macintosh
     
JB72  (op)
Mac Elite
Join Date: Jan 2001
Location: L.A., CA
Status: Offline
Reply With Quote
Apr 19, 2003, 07:51 PM
 
Originally posted by Rainy Day:
As regards the configuration file setup, it is best not to edit http.conf directly under MacOS X. Notice the last line of Apple's http.conf file:

   Include /private/etc/httpd/users
[/code]
Thanks Rainy Day.

I heard something about that but wasn't sure how it worked. Any advice for those who have already editied the wrong httpd.conf? Should I go back and re-edit to original? Can I copy the edited file to the /private/ version?

back to virtual hosts...

I found the following comment at MacDevcenter:

I grew impatient and figured out a way to do this myself -- it was extremely easier than I thought it would be. Standard disclaimer applies: it worked for me, but I take no responsibility

Step 1:
-------

Load up your http.conf file (/etc/httpd/httpd.conf) in your favorite text editor, and uncomment the following lines by removing the pound sign (#):

#LoadModule vhost_alias_module libexec/httpd/mod_vhost_alias.so

#AddModule mod_vhost_alias.c


Step 2:
-------

Search for the following line:

UseCanonicalName On

... and turn it off by changing it to:

UseCanonicalName Off


Step 3:
-------
Add the following line right below the last one you modified in step 2:

VirtualDocumentRoot /Library/WebServer/Documents/%0

Basically this says reroute to the folder that matches the server name. i.e. http://www.foo.com -> /Library/WebServer/Documents/www.foo.com/ In theory, you could use any folder, but I chose to simply repurpose my webserver documents directory.


Step 4:
-------
Save the file and restart your web server (turn web sharing off and then on again).


Now the trick to getting this to work completely is to simply create folders for each domain name you want to host virtually. For example, say you have two sites: www.foo.com and www.bar.com. In your webserver documents folder, you'd simply create folders with the same names:

/Library/WebServer/Documents/www.foo.com
/Library/WebServer/Documents/www.bar.com

And put the files for each site in the respective folders.

Magic!

Note that you might need to tweak this to get www.foo.com and foo.com to point to the same place (using aliasing, I'd imagine). You can read all about the vhost_alias module and VirtualDocumentRoot directive at http://httpd.apache.org/docs/mod/mod_vhost_alias.html
Does that seem reasonable? What's with the "UseCanonicalName" directive? Should I be modifying that?

Thanks again for your advice. Without helpful forums, my Macs would be hosed a long times ago.
     
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Apr 19, 2003, 09:33 PM
 
Any advice for those who have already editied the wrong httpd.conf? Should I go back and re-edit to original?
The choice is somewhat arbitrary, but if it were me, i'd drop back to the original, just to avoid headaches later.

Can I copy the edited file to the /private/ version?
Well, you can, but you really shouldn't. Better to do a diff with the original and copy only the additions on over.

back to virtual hosts...

I found the following comment at MacDevcenter:

Does that seem reasonable?
Not really. Apache is able to serve up virtual hosts without adding the overhead of invoking additional modules. All that is required is the configuration i gave you above. You can choose to serve out of any directory you want with it too.

What's with the "UseCanonicalName" directive? Should I be modifying that?
You shouldn't be modifying any directive you don't understand. Apache has wonderful documentation with every directive explained in detail. It is available both online and on your MacOS X HD (and i believe Apple's default MacOS X web page points to the local doc's).

Additionally, the book Professional Apache 2.0 is an excellent reference. It's the best Apache book i've seen. It also goes beyond Apache documentation by explaining how to tweak Apache for speed, security, etc.
     
JB72  (op)
Mac Elite
Join Date: Jan 2001
Location: L.A., CA
Status: Offline
Reply With Quote
Apr 20, 2003, 08:17 PM
 
The choice is somewhat arbitrary, but if it were me, i'd drop back to the original, just to avoid headaches later.
That sounds like a good idea. But the issue with the .bak files already has me confused. Is there something I modify to set the new backup directory?

Not really. Apache is able to serve up virtual hosts without adding the overhead of invoking additional modules. All that is required is the configuration i gave you above. You can choose to serve out of any directory you want with it too.
That sounds more like it. Your config looks less "hackish."

You shouldn't be modifying any directive you don't understand.
I'm afraid I wouldn't be modifying anything at all in Apache then.

Additionally, the book Professional Apache 2.0 is an excellent reference. It's the best Apache book i've seen. It also goes beyond Apache documentation by explaining how to tweak Apache for speed, security, etc. [/B]
I got a chance to browse this at a Borders today. Looks really good, not as intimidating as I might have expected, but it's aimed only at Apache 2 right? I'm running the built-in 1.3.x.

Thanks again for the help. I'm out of town right now so I haven't had a chance to try out the virtual hosting yet. Although I might SSH in and pico my httpd.conf. I'm addicted.
     
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Apr 22, 2003, 12:57 PM
 
That sounds like a good idea. But the issue with the .bak files already has me confused.
Any file in /private/etc/httpd/users/, regardless of its name or suffix, is appended to your /etc/httpd/httpd.conf file. If your editor automatically creates backup files in the same directory as the original, you may end up with backup files in the /private/etc/httpd/users/ directory, and they will probably cause you grief.

If you take care to ensure that the only files in /private/etc/httpd/users/ are active configuration files and none others, you'll have no problems.

Is there something I modify to set the new backup directory?
That depends on the editor you're using and how it's configured, so there's no one answer to your question. I haven't used command line editors like pico since 1984, so i'm not qualified to comment on how to configure them.

One solution is to edit the files in a separate directory, and copy it into /private/etc/httpd/users/ when you're ready to bring it online. One could even write a shell script to copy files over, and restart Apache.

Another solution is to simply ensure your editor doesn't create backup files in the same directory.

Another solution is to write a shell script to remove (or move) the backup files from /private/etc/httpd/users/, and restart Apache.

There are any number of solutions to this problem. One could also write an AppleScript to do this.

I got a chance to browse this at a Borders today. Looks really good, not as intimidating as I might have expected, but it's aimed only at Apache 2 right? I'm running the built-in 1.3.x.
The book covers both 1.3 and 2.0 and is very good in letting you know if anything they're talking about is specific to one version or the other.
     
JB72  (op)
Mac Elite
Join Date: Jan 2001
Location: L.A., CA
Status: Offline
Reply With Quote
Apr 22, 2003, 06:16 PM
 
TY Rainy Day. You've been extremely helpful.

Last night I got my virtual hosts set up. Between the Apache docs and your example it was a breeze. I don't know what I was worried about. I even had a chance to drop Simple Forum into my little network. I'm loving it.

Now if I can get a proper ftp server running and tighten up the security, I'll be ready to introduce some decent content.

- t h a n x -
     
Grizzled Veteran
Join Date: Nov 2001
Location: Oregon
Status: Offline
Reply With Quote
Apr 22, 2003, 07:30 PM
 
Glad to hear you got it going. You're right, Apache really isn't that hard to get going. It just looks that way at first glance.

Regarding an ftp server, may i ask what you plan to use it for? I ask this because ftp is really a security risk as passwords are sent in the clear. This means it's possible for someone to eavesdrop traffic to your server and gain both user ID and passwords to it. That makes an attack much easier for the bad guys.

If your interest in an ftp server is merely to maintain the server, i'd recommend setting up an sshd server and use rsync to transfer files via an ssh tunnel. A secure version of ftp, sftp, is also an option. But rsync can be a really good way to go for a lot of applications. rsync comes pre-installed on MacOS X, as is ssh.
     
JB72  (op)
Mac Elite
Join Date: Jan 2001
Location: L.A., CA
Status: Offline
Reply With Quote
Apr 23, 2003, 07:09 PM
 
Originally posted by Rainy Day:
Glad to hear you got it going. You're right, Apache really isn't that hard to get going. It just looks that way at first glance.
Apache is actually kind of addicting in a way. A sick kind of fun. Instant results and all that.

Regarding an ftp server, may i ask what you plan to use it for? I ask this because ftp is really a security risk as passwords are sent in the clear.
FTP Access stopped.

If your interest in an ftp server is merely to maintain the server, i'd recommend setting up an sshd server and use rsync to transfer files via an ssh tunnel. A secure version of ftp, sftp, is also an option. But rsync can be a really good way to go for a lot of applications. rsync comes pre-installed on MacOS X, as is ssh.
Those sound like better options. I need sucure access for select guests to upload html stuff to their sites folders. I'm looking at Windows users with limited knowledge of things like sshd and rsync (although I use Fugu, and rsync GUI for local stuff.) Something built into Dreamweaver would be the ideal.

OK, off to see a demo of FCP4 at the Digital Cinema Lab. More servery stuff later. )
     
   
Thread Tools
Forum Links
Forum 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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 03:24 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2