Apache Virtual Hosts

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

I'm trying to setup virtual hosts on my machine, and they're not really working.

My IP is 72.72.72.72 (my ISP does not block port 80). I setup a virtual host for mytestdomain.com. I point my DNS over to 72.72.72.72 and go to mytestdomain.com and I get /var/www. In my virtual host file, the document root is set to /var/www/mytestdomain.com.

Get what I'm saying? I'm not sure what I'm supposed to do. Any ideas?

I'm using webmin to set them up.

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

Arg, why do I figure it out right after I post it?

In my apache2.conf file, I had to move

Include /etc/apache2/sites-enabled/[^.#]*

below my virtual hosts. You think any sites on the internet would mention that little tidbit? Nope.

Megan's picture

She has: 11,421 posts

Joined: Jun 1999

teammatt3 wrote: Arg, why do I figure it out right after I post it?

Oh, you're not the only one who does that!

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

That's weird that you have to manually have to edit a config file. When I create a virtual host through Webmin on my home server, I have my settings like this:

I read in a tutorial that the two checkboxes towards the top should be unchecked due to a bug in Webmin. That was a couple years ago that I read it, so the bug may or may not still be there. Nevertheless, I still uncheck them and never have a problem.

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

Well, because I like to do things the hard way, I decide to click the "Standard httpd.conf file" option. That wrote the virtual hosts to the bottom of the apache2.conf file. Because the include line was still in there (before my virtual hosts), it was reading the data from sites-enabled directory first (and the default host is kind of like a catch all) so my virtual hosts weren't getting any attention. I think that's what was happening.

I deleted that default host, and added my own hosts with the "New file under virtual server directory..." option and it seemed to work ok.

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

Just out of interest: does a2ensite <sitename> --from the command line--work?

teammatt3's picture

He has: 2,102 posts

Joined: Sep 2003

When I run it with a site I setup, I get "This site is already enabled".

I guess it works.

JeevesBond's picture

He has: 3,956 posts

Joined: Jun 2002

Cool, just a FYI: you can also use a2dissite <sitename> to disable sites. Maybe easier than fiddling with symlinks. Smiling

ohrana's picture

They have: 156 posts

Joined: Sep 2006

Like it. It's great.

tummy's picture

They have: 121 posts

Joined: Mar 2007

Has it still been working?

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.