PDA

View Full Version : VirtualHost in httpd.conf?



adrianboyko
10-13-2003, 10:27 AM
I'm curious to hear if anybody with a dedicated IP address has tried to set up name-based virtual hosting by adding something like the following to their httpd.conf:

NameVirtualHost *

<VirtualHost *>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

When doing this, must the preexisting domain (www.domain.tld in this example) into a VirtualHost element? Or can one leave httpd.conf the way it is, and simply add a single VirtualHost element for the additional domain (www.otherdomain.tld in this example)?

I've already got DNS appropriately configured, with both of my domains resolving to my dedicated IP at WestHost. Just wondering if there are any httpd.conf gurus who can clarify the Apache configuration issue for me.

Thanks!
Adrian

wildjokerdesign
10-13-2003, 12:02 PM
When you add a domain via your Site Manager it adds what your are speaking of above to your httpd.conf with a few diffrences.

ServerName otherdomain.com
ServerAlias www.otherdomain.com
DocumentRoot depends on what you enter

Does that answer your question?

Shawn

adrianboyko
10-13-2003, 08:55 PM
Thanks for the info... I decided to experiment with httpd.conf and it seems like I only need to create a single VirtualHost leaving the "main" configuration to catch the rest of the requests. I added something like this:

NameVirtualHost *
<VirtualHost *:8080>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

I don't want to specify port 8080, but I can only get the VirtualHost to catch requests if I specify that it is on port 8080. The server switches between my main and virtual server depending on which port I specify:

www.domain.tld --> main
www.domain.tld:80 --> main
www.otherdomain.tld --> main
www.otherdomain.tld:80 --> main
www.domain.tld:8080 --> virtual
www.otherdomain.tld:8080 --> virtual

Can't seem to get it to switch on the basis of the request's "Host:" header. I guess that the configuration for the "main" server is somehow matching *any* request to port 80 on my dedicated IP address, no matter what the "Host:" header says, but I don't know what aspect of the "main" configuration would be responsible for that behavior.

Adrian

wildjokerdesign
10-13-2003, 09:18 PM
I have you checked this page out yet http://httpd.apache.org/docs/vhosts/ ? It sounds like maybe you are a bit more knowlegable when it comes to this area then I am. I am trying to muddel through and learn as much as I can and just how much control we really have with this VDS and Virtual Host thing.

I am working with some other users to figure out if with the virtual host you can keep the thierdomain.com showing up after a browser goes to a second directory in the thierdomain area i.e. if you had thierdomain.com/somedirectory/page.html it show in the address as yourdomain.com/somedirectory/page.html. This may be a seprate issue compleatly like I say I am just muddeling through.

Shawn

P.S. How did you edit the httpd.conf... via SSH or did you download via FTP and the uplaod it again.

jalal
10-14-2003, 02:02 AM
Adrian

When you put:
NameVirtualHost *
<VirtualHost *:8080>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

you are telling apache that anything on port 8080 is to be mapped to the 'otherdomain.tld'. Otherwise the default is to pass all connections to 'domain.tld'

You need something like this:

<VirtualHost otherdomain.tld>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

adrianboyko
10-14-2003, 11:56 AM
Hi Jalal,

Yes, I understand what you're saying, but I already tried the sort of VirtualHost config you've suggesting (and even retried it again after reading your posting) and it doesn't work. It seems straightforward enough to configure a named vhost as per your example (or the various FAQs on the web), but it just doesn't work for me here -- probably because of something specified in the "main" server config.

My point with the port 8080 example was to show that it is indeed possible to configure *some sort of virtual host*. I don't actually want my vhost on port 8080, but at least I've convinced myself that vhosts in general are possible.

Adrian

adrianboyko
10-14-2003, 12:04 PM
have you checked this page out yet http://httpd.apache.org/docs/vhosts/ ?

Yep, I've read a number of vhost FAQs. It all seems pretty simple, but I must be missing some key point.


How did you edit the httpd.conf... via SSH or did you download via FTP and the uplaod it again.

Since the changes I'm making are minor, I log on via SSH and then use "pico" to edit the file. Pico probably seems like a strange choice, but I got used to it many years ago when I used Pine for email. If I had to do more extensive editing, I suppose I'd FTP the file to my Windows machine and use UltraEdit.

jalal
10-14-2003, 02:07 PM
Hi Adrian

Pity, its *supposed* to work like that :)

Dragging out the Apache manual here, I notice that they put the IP address in the NameVirtualHost directive, like so:
=========
NameVirtualHost 69.36.162.101
<VirtualHost domain.tld>
ServerName www.domain.tld
DocumentRoot /www
</VirtualHost>
<VirtualHost otherdomain.tld>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>
=========

Maybe worth a try?

REC-WH
10-14-2003, 02:12 PM
I'm curious to hear if anybody with a dedicated IP address has tried to set up name-based virtual hosting by adding something like the following to their httpd.conf:

NameVirtualHost *

<VirtualHost *>
ServerName www.domain.tld
DocumentRoot /www/domain
</VirtualHost>

<VirtualHost *>
ServerName www.otherdomain.tld
DocumentRoot /www/otherdomain
</VirtualHost>

When doing this, must the preexisting domain (www.domain.tld in this example) into a VirtualHost element? Or can one leave httpd.conf the way it is, and simply add a single VirtualHost element for the additional domain (www.otherdomain.tld in this example)?

I've already got DNS appropriately configured, with both of my domains resolving to my dedicated IP at WestHost. Just wondering if there are any httpd.conf gurus who can clarify the Apache configuration issue for me.

Thanks!
Adrian

I have tried to setup virtualhosts and I couldn't get it to work. I am a novice, but I have set them up up Windows2000 & Apache. If you look in the conf, file under your domain name, there is a listing at line number 429 "group vuser". I think this must refer to the additional domain name pointed to your account. I have search for this file and couldn't find it. It may refer to a master server file somewhere? I am not sure Apache works the same under this VDS system. I think you will also have to add the domain names under ServerName if it will let you.

I have not tried to many changes because of all the current problems under WH2. Right now I am happy having a site that is up :D

Charlie

adrianboyko
10-16-2003, 04:34 PM
If you look in the conf, file under your domain name, there is a listing at line number 429 "group vuser". I think this must refer to the additional domain name pointed to your account. I have search for this file and couldn't find it. It may refer to a master server file somewhere?

"vuser" is just the name of the group that your login account belongs to. File permissions in *nix are based on your userid and groupid. If this is new to you, try looking for "group user permissions tutorial" on Google.

The line you mention in httpd.conf tells the server what user and group it should run as. Since file access permissions are based on user and group, this will affect what your server can and can't access while running.

At least that's the way I understand it.

REC-WH
10-16-2003, 08:00 PM
If you look in the conf, file under your domain name, there is a listing at line number 429 "group vuser". I think this must refer to the additional domain name pointed to your account. I have search for this file and couldn't find it. It may refer to a master server file somewhere?

"vuser" is just the name of the group that your login account belongs to. File permissions in *nix are based on your userid and groupid. If this is new to you, try looking for "group user permissions tutorial" on Google.

The line you mention in httpd.conf tells the server what user and group it should run as. Since file access permissions are based on user and group, this will affect what your server can and can't access while running.

At least that's the way I understand it.

If you just add a additional domain name it does not modify the httpd.conf file. If you select "custom directory" when you adding the domain name it modifies the hpptd.conf and add the following:

<VirtualHost *>
ServerName real-domain1.biz
ServerAlias www.real-domain1.biz
DocumentRoot /var/www/tryl
</VirtualHost>

I used real-domain1.biz and /var/www/try as an example.
At least that's the way it works for me!

CM

adrianboyko
10-21-2003, 11:40 PM
Yep, I've read a number of vhost FAQs. It all seems pretty simple, but I must be missing some key point.

Just thought I'd post a followup to let any readers know that I did get the vhosts working. I'm not sure, but I think the problem was that I had too many httpd processes running. I happened to notice that there were some left even after doing an "apachectl stop". After I killed them and restarted with "apachectl start", everything started working as expected.

I did see a message somewhere else on the web where somebody responding to a vhost problem suggested "kill -TERM"ing all the httpd processes before restarting, so I guess I should have paid more attention to that particular suggestion earlier on. I suppose this might be good advice for anybody struggling with any sort of httpd.conf problem.

Adrian