LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   apache2 setup/test subdomains on LAN (http://www.linuxquestions.org/questions/linux-server-73/apache2-setup-test-subdomains-on-lan-595051/)

DeltaXFX 10-27-2007 12:34 PM

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

JimBass 10-27-2007 02:09 PM

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

DeltaXFX 10-27-2007 03:28 PM

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.

JimBass 10-27-2007 04:35 PM

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

DeltaXFX 11-03-2007 08:01 PM

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.

JimBass 11-04-2007 10:16 AM

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

Peace,
JimBass


All times are GMT -5. The time now is 04:50 PM.