LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-27-2007, 12:34 PM   #1
DeltaXFX
Member
 
Registered: Feb 2004
Location: USA
Distribution: Arch
Posts: 30

Rep: Reputation: 15
apache2 setup/test subdomains on LAN


Hi,

I got my AMP stack running a few days ago and was wanting to get more into it. But am having problems with virtual hosts in apache.

I am just doing testing on my LAN at the moment. But will probably go with something like dyndns if I can get everything working.

Apache2 is working fine, I can see the test page, even MySQL and PHP5 are working, and it only took a couple tries :P I installed bblog to test out the MySQL and PHP5.

My original directory structure was:
/usr/local/apache2/htdocs < apache test page in there
/usr/local/apache2/htdocs/blog < bblog in there

I could access both fine by just using my IP, 192.168.1.110 for the test page, and /blog for the bblog.

I like the subdomain way better, ie www.mydomain, blog.mydomain but I cannot get it working. Is it not possible to do this by IP on a LAN?

I have changed my directory structure around to make a little more sense:

/usr/local/apache2/htdocs/www < is document root
/usr/local/apache2/htdocs/www/www < apache test page
/usr/local/apache2/htdocs/www/blog < bblog

Here are the important parts of my httpd.conf:

### Section 1: Global Environment
ServerRoot "/usr/local/apache2"
Listen 80

### Section 2: 'Main' server configuration
ServerName 192.168.1.110

DocumentRoot "/usr/local/apache2/htdocs/www"

<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

<Directory "/usr/local/apache2/htdocs/www">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>

### Section 3: Virtual Hosts
<VirtualHost *>
DocumentRoot "/usr/local/apache2/htdocs/www/www"
ServerName www.192.168.1.110
</VirtualHost>
<VirtualHost *>
DocumentRoot "/usr/local/apache2/htdocs/www/blog"
ServerName blog.192.168.1.110
</VirtualHost>


Am I doing something wrong there? I also tried what I found at this site, http://www.megalinux.net/archives/649.html, but couldn't get it to work, so tried just making a virtualhost for each subdomain I wanted, found here, http://ubuntuforums.org/archive/index.php/t-394618.html Can you only use virtual hosts if you actually have a domain assigned to you? Or is it possible to do it by IP? Or do I just have it all wrong? I'm betting on the last one, thats why I'm asking you guys :P
 
Old 10-27-2007, 02:09 PM   #2
JimBass
Senior Member
 
Registered: Oct 2003
Location: New York City
Distribution: Debian Sid 2.6.32
Posts: 2,100

Rep: Reputation: 49
Its the last one, but at least you realized that possibility!

The problem is your virtual hosts setup. you used the wildcard *, so it can't separate one * from the other. The more correct way to setup the 2 virtual domains you had in question would be:

Code:
<VirtualHost www.domain.com:80>
DocumentRoot "/usr/local/apache2/htdocs/www/www"
ServerName www.192.168.1.110
</VirtualHost>
<VirtualHost blog.domain.com:80>
DocumentRoot "/usr/local/apache2/htdocs/www/blog"
ServerName blog.192.168.1.110
</VirtualHost>
You can change the domain.com to 192.168.1.110 if that makes you happy, but the way I did it, when you make it live to the public, you don't have to change anything. I wouldn't announce the LAN IP of the server, but you can.

Peace,
JimBass
 
Old 10-27-2007, 03:28 PM   #3
DeltaXFX
Member
 
Registered: Feb 2004
Location: USA
Distribution: Arch
Posts: 30

Original Poster
Rep: Reputation: 15
I thought the * might be the problem, but the sites I had been reading were not very specific. However, I still haven't gotten it working.

My virtual hosts setup now looks like:

Code:
<VirtualHost www.192.168.1.110:80>
    DocumentRoot "/usr/local/apache2/htdocs/www/www"
    ServerName www.192.168.1.110
</VirtualHost>
<VirtualHost blog.192.168.1.110:80>
    DocumentRoot "/usr/local/apache2/htdocs/www/blog"
    ServerName blog.192.168.1.110
</VirtualHost>
But no joy. Now when I stop or start apache I get the following error.
Code:
[Sat Oct 27 22:36:06 2007] [error] (EAI 8)node name or service name not known: Cannot resolve host name www.192.168.1.110 --- ignoring!
[Sat Oct 27 22:36:06 2007] [error] (EAI 8)node name or service name not known: Cannot resolve host name blog.192.168.1.110 --- ignoring!
So I changed the virtual hosts section to:
Code:
<VirtualHost www.surefire.home:80>
    DocumentRoot "/usr/local/apache2/htdocs/www/www"
    ServerName www.192.168.1.110
</VirtualHost>
<VirtualHost blog.surefire.home:80>
    DocumentRoot "/usr/local/apache2/htdocs/www/blog"
    ServerName blog.192.168.1.110
</VirtualHost>
And get the same errors but with the hostname instead of IP

So its got to be in the hosts somewhere. If I change the /etc/hosts on the sever to be:
Code:
127.0.0.1       localhost
192.168.1.110   surefire surefire.home www.surefire.home blog.surefire.home
I get the following error:
Code:
[Sat Oct 27 22:58:47 2007] [warn] VirtualHost www.surefire.home:80 overlaps with VirtualHost blog.surefire.home:80, the first has precedence, perhaps you need a NameVirtualHost directive
I changed the /etc/hosts on the computer I'm trying to connect to the server with to:
Code:
127.0.0.1       localhost.localdomain   localhost lite.home lite
192.168.1.110   surefire.home  surefire www.surefire.home blog.surefire.home
Now, once I changed the hosts on the computer I'm connecting with I can get to www.surefire.home and it brings up the apache test page like it should. But I can't get to the blog page. If I try blog.surefire.home I get the apache test page again, instead of the blog. Probably makes sense because of the error that www has precedence over blog. But if I take the www.surefire.home blog.surefire.home back out of the servers /etc/hosts I just get a file list of /usr/local/apache2/htdocs/www (which has the directories 'blog' and 'www') when I go to surefire.home or www.surefire.home. And get the apache test page when I go to blog.surefire.home
Oh. And I restart httpd after every change just to make sure.
 
Old 10-27-2007, 04:35 PM   #4
JimBass
Senior Member
 
Registered: Oct 2003
Location: New York City
Distribution: Debian Sid 2.6.32
Posts: 2,100

Rep: Reputation: 49
The problem has nothing to do with your hosts file, it is all an apache config.

I may have copied too quickly from one of my servers and not paid enough attention. I left out the NameVirtualHost call, it should look like this:

Code:
NameVirtualHost 192.168.1.110:80
<VirtualHost www.surefire.home:80>
so forth
</VirtualHost>
NameVirtualHost 192.168.1.110:80
<VirtualHost blog.surefire.home:80>
stuff
</VirtualHost>
I still STRONGLY suggest taking out the ServerName with the IP address. Since you're going to get the errors anyway about the unknown name, do yourself a favor and make the name what you are going to call the site.

Peace,
JimBass

Last edited by JimBass; 10-27-2007 at 04:36 PM. Reason: typo
 
Old 11-03-2007, 08:01 PM   #5
DeltaXFX
Member
 
Registered: Feb 2004
Location: USA
Distribution: Arch
Posts: 30

Original Poster
Rep: Reputation: 15
Success!

Thank you for all your help and patience JimBass!
Heres what I did to finally get everything working.
-Set up a DNS server on my LAN
---Directed surefire.home to 192.168.1.110
---Setup a CNAME of *.surefire.home to surefire.home

-Edited httpd.conf, important parts:
Code:
ServerName surefire.home

<VirtualHost *>
    ServerAlias *.surefire.home
    VirtualDocumentRoot /usr/local/apache2/htdocs/www/%0
</VirtualHost>
So anytime I make a subdomain I can just add it under www/
i.e. if I want blog.surefire.home I make the directory /usr/local/apache2/htdocs/www/blog.surefire.home and put everything for that subdomain in there.
 
Old 11-04-2007, 10:16 AM   #6
JimBass
Senior Member
 
Registered: Oct 2003
Location: New York City
Distribution: Debian Sid 2.6.32
Posts: 2,100

Rep: Reputation: 49
Adding a DNS server seems like more work than was necessary, but if it works for you, cool.

Peace,
JimBass
 
  


Reply

Tags
apache2, domains, host, ip, lan, sub, virtual



Posting 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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Apache2 Virtual host on LAN jordankoppole Linux - Software 4 10-16-2007 09:57 AM
Apache2 - ab - stress test grant-skywalker Linux - Server 0 07-24-2007 05:45 AM
Apache2 Installed But Unable to Start and Test rforrister Linux - Server 5 03-19-2007 12:43 PM
Subdomains on Apache2 with virtual hosts - how? <Ol>Origy Linux - Networking 2 08-18-2005 05:53 AM
how do i test apache2? clueless_user Linux - Newbie 3 09-04-2004 03:11 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 06:26 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration