A little help with virtual host on apache2

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

A little help with virtual host on apache2

Post 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. :?
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

127.0.0.1 localhost.localdomain localhost news.com http://www.news.com phptest.com http://www.phptest.com
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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"... :)
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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)
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I need more help :oops: What do I do? I tried

Code: Select all

NameVirtualHost 127.0.0.1
And it told me 127.0.0.1 has no virtualhosts ... ? :?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Ok it's miraculously working now. I'm not sure what I did to make it work though. :?
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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? :x :(
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

why does it keep saying "cannot determine the server's fully qualified domain name"? :( nobody has a clue?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Post by califdon »

I feel your pain! :cry: 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!
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post 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?
Post Reply