Page 1 of 1
A little help with virtual host on apache2
Posted: Sat Jan 13, 2007 3:04 pm
by Luke
I set up a virtual (name-based) host on apache by putting this file in /etc/apache2/sites-enabled and then linked it to sites-available
news.com.conf
Code: Select all
<VirtualHost news.com>
ServerAdmin webmaster@localhost
ServerAlias www.news.com
DocumentRoot /home/luke/sites/news.com
</VirtualHost>
Then I edited my /etc/hosts file adding this line:
Code: Select all
127.0.0.1 localhost.localdomain localhost news.com www.news.com
Then I restarted apache, typed in
http://www.news.com in my url and wa-la! it worked! Now... i want to add another site called phptest.com. So I followed those steps again, and then typed in phptest.com and it took me to /home/luke/sites/news.com instead of /home/luke/sites/phptest.com
here's the other conf file:
Code: Select all
<VirtualHost phptest.com>
ServerAdmin webmaster@localhost
ServerAlias www.phptest.com
DocumentRoot /home/luke/sites/phptest.com
</VirtualHost>
what do I add to the /etc/hosts file now? I'm a little confused.

Posted: Sat Jan 13, 2007 3:12 pm
by nickvd
127.0.0.1 localhost.localdomain localhost news.com
http://www.news.com phptest.com
http://www.phptest.com
Posted: Sat Jan 13, 2007 3:21 pm
by Luke
Yea I tried that... When I restart apache I get this message (if I change /etc/hosts file to say that)
apache2: Could not determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[Sat Jan 13 13:19:34 2007] [warn] VirtualHost news.com:0 overlaps with VirtualHost phptest.com:0, the first has precedence, perhaps you need a NameVirtualHost directive
And then it still takes me to news.php's directory when I type in phptest.com
I'm going to go look up "NameVirtualHost"...

Posted: Sat Jan 13, 2007 3:26 pm
by nickvd
If you need more help, let me know... Assuming you know how to read

What you find on namevirtualhost will answer all your questions.. I thought you were already using it (name based virtual hosting versus ip based virtual hosting)
Posted: Sat Jan 13, 2007 4:08 pm
by Luke
I need more help

What do I do? I tried
And it told me 127.0.0.1 has no virtualhosts ... ?

Posted: Sat Jan 13, 2007 5:01 pm
by Luke
Ok it's miraculously working now. I'm not sure what I did to make it work though.

Posted: Wed Sep 19, 2007 2:04 pm
by Luke
We just got a dedicated box from slicehost. I'm having this problem again. It's saying "cannot determine the server's fully qualified domain name" when I try to restart or stop apache. I have not set up any virtual hosts, but I do have a domain name pointed at it.
Why would it be doing this? I was able to restart it before, but I must have done something to make it mad.
Posted: Fri Sep 21, 2007 6:35 pm
by Luke
Nobody has any idea?

I keep reading that I have to edit my hosts file and put in my hostname and domain name. I don't know what those are... everything I've see just assumes I readily know what my host and domain name are. I don't have a clue.

I'm new to server configuration. Somebody help the n00b please.
I don't understand why I need a domain name just to start apache... what's wrong with localhost?

Posted: Mon Sep 24, 2007 11:13 am
by Luke
why does it keep saying "cannot determine the server's fully qualified domain name"?

nobody has a clue?
Posted: Mon Sep 24, 2007 12:49 pm
by pickle
So there are no problems at all when you just have news.com? The problem only manifests itself when you modify your hosts file?
Is the modifying of the hosts file only necessary when making name-based virtual hosts? The reason I ask is because I've got a server at my work that has 4 different subdomains running off it, but they're all ip-based. We haven't modified our /etc/hosts file once for any of those subdomains.
Another shot in the dark is DNS. Is news.com in your NDS servers but phptest.com is not? Maybe it's a reverse-lookup problem?
Posted: Mon Sep 24, 2007 1:29 pm
by Luke
I just started with a brand new linux install. I installed apache2 and now I'm trying to restart it. Whenever I do that, it tells me "cannot determine the server's fully qualified domain name" and it won't restart. I probably shouldn't have recycled this thread, but this is the same error I was getting when I originally posted this thread. This is a new issue. What is causing this?
Posted: Mon Sep 24, 2007 2:11 pm
by califdon
I feel your pain!

I ran Apache on a home server connected to a single IP DSL for several years, using named virtual hosting for a half dozen domains. It is far from intuitive! It was not Apache2, so there may be some differences. If it will help, here are some observations:
The reason Apache needs a fully qualified domain name is that it has to know what requests to respond to.
Running it as localhost (127.0.0.1) is different than running it as an external Internet server.
There are several files that are involved in named virtual hosting. The local etc/hosts file only has to do with resolving domain names that are generated from the local computer (to shortcut going out to DNS), not incoming requests from the Internet.
http://www.faqs.org/docs/securing/chap9sec95.html. The virtual host name detection relies on the other files, like sites-enabled/sites-available, and (I think) http.conf.
It has been a year or so since I migrated to a hosting service, so my memory of the detailed techniques has faded somewhat. I do remember that I learned a whole new vocabulary of 4-letter words while I was getting it all to work. My best suggestion is to scour the net for explanations of how named virtual hosting really works, not just little examples. That way lies madness. Once you actually understand how it works, it will be simple. Trust me!
Posted: Mon Sep 24, 2007 2:43 pm
by Luke
I haven't even got to the point of configuring virtual hosting. I need to be able to restart my server before I can configure. Right now it insists on the "fully qualified domain name" and I don't know what that is, nor can I find out on the internet anywhere. Everything just tells me to put "servername.domainname" in my hostname file. I don't know what my domain name is!!

Right now I don't think I have one.
Posted: Wed Sep 26, 2007 12:28 am
by nickvd
That's just a warning... apache should still run just fine. Are you sure that localhost (or whatever 'servername' is) is included in your hosts file?