# Apache Virtual Hosting (3 options)

## Shiner_Man

I've been reading some threads on the forums and looking at some documentation on apache's site.  It seems that their are 3 different ways to go about setting up virtual hosts.

1.  Name based

2.  IP address based

3.  Dynamic based

Currently I'm using the Name based approach since it is the easiest to do.  It works fine but now I've run into a problem.

I use squirrelmail to check my local email remotely and I also use the forced ssl login plugin so that everything is encrypted during login.  This is where the problem occurs.  I can access my mail by going to:

http://www.mydomian.com/squirrelmail

I want to be able to access squirrelmail through:

http://mail.mydomain.com

Apparently this is not possible using named based virtual hosting since ssl can not be used with it.  The next option is IP based virtual hosting but I only have on IP address so that is out as well.

My question is, will the dynamic virtual hosting setup work and if so how do I set it up?  I basically have three domains I want to run using virtual hosting:

http://www.mydomain.com  -  main site

http://gallery.mydomain.com  -  gallery

http://mail.mydomain.com   -  squirrelmail

Any help would be appreciated.

----------

## splooge

Not entirely sure I understand the problem with this whole "can't do virtual hosting with ssl" thing.  I've read about it, straight from the apache site, and I think ... well, I think there's more than one way to skin a cat.

I think you CAN run more than one site on a secure server, but they will all be forced to use the same certificate.

https://fw.pwned.com

https://mail.pwned.com

Both the same web server.  I used the mod_rewrite rules posted by Delta407 on the "Virtual Hosting Made Easy" thread in the DT&T forum.  Good luck.

----------

## RedDawn

 *Shiner_Man wrote:*   

> I've been reading some threads on the forums and looking at some documentation on apache's site.  It seems that their are 3 different ways to go about setting up virtual hosts.
> 
> 1.  Name based
> 
> 2.  IP address based
> ...

 

YES YOU CAN!! THAT HOW I DO IT!1

http://mail.yourowndisaster.net   <-- it automatically send you to HTTPs

here my vhost conf!!

```

<VirtualHost *:80>

ServerName mail.yourowndisaster.net

ServerAlias www.mail.yourowndisaster.net

DocumentRoot /var/www/localhost/htdocs/squirrelmail

RewriteEngine on

RewriteRule ^/(.*) https://mail.yourowndisaster.net/$1 [R,L]

</VirtualHost>

<VirtualHost *:443>

ServerName mail.yourowndisaster.net

ServerAlias www.mail.yourowndisaster.net

DocumentRoot /var/www/localhost/htdocs/squirrelmail

</VirtualHost>

```

And You did set your DNS server correctly right. 

Having the DNS entries right.. 

ie... mail.yourowndisaster.net  resolves to 12.12.12.12  is so all you have to do is put that configuration in your vhost file..  and enable ssl in your apache configuration if u nned help doing that.. post it here ill be back later or tomoroow.. is easy..

all you have to do is LOAD the ssl module when apache start..

Well i hope i helped you.   :Cool: 

----------

## Shiner_Man

 *RedDawn wrote:*   

> 
> 
> YES YOU CAN!! THAT HOW I DO IT!1
> 
> http://mail.yourowndisaster.net   <-- it automatically send you to HTTPs
> ...

 

hmmm...so your not using the squirrel mail plugin for secure login.  You are using mod_rewrite to force it to go through ssl.  Perhaps the squirrelmail module is what is messing things up.  

I'll give it a try.

<UPDATE>

Okay I did what you said and I'm getting two issues.  First off when I restart apache I get this error message:

```
[warn] _default_ VirtualHost overlap on port 443, the first has precedence
```

Secondly, if I go to http://mail.shinerman.net  it does force ssl use but I'm getting the site for my document root(/var/www/localhost/htdocs) rather then the squirrelmail directory(/var/www/localhost/htdocs/squirrelmail).

Here is my vhosts.conf file:

```
NameVirtualHost *:80

<VirtualHost *:80>

ServerName www.shinerman.net

DocumentRoot /var/www/localhost/htdocs

</VirtualHost>

<VirtualHost *:80>

ServerName forums.shinerman.net

DocumentRoot /var/www/localhost/htdocs/phpBB

</VirtualHost>

<VirtualHost *:80>

ServerName gallery.shinerman.net

DocumentRoot /var/www/localhost/htdocs/gallery

</VirtualHost>

<VirtualHost *:80>

ServerName mail.shinerman.net

DocumentRoot /var/www/localhost/htdocs/squirrelmail

RewriteEngine on

RewriteRule ^/(.*) https://mail.shinerman.net/$1 [R,L]

</VirtualHost>

<VirtualHost *:443>

ServerName mail.shinerman.net

DocumentRoot /var/www/localhost/htdocs/squirrelmail

</VirtualHost>
```

----------

## splooge

I don't like the vhost system that comes with apache.  Did you try searching for what I recommended?  Here, I'll post the relevant info.  All credit goes to Delta407:

Stick this in your apache2.conf:

```
RewriteEngine On

RewriteMap  lowercase  int:tolower

RewriteCond  /var/www/${lowercase:%{SERVER_NAME}} -d

RewriteRule  ^/(.*)$  /var/www/${lowercase:%{SERVER_NAME}}/$1 [L]

RewriteRule  ^/(.*)$  /var/www/default/$1
```

In commonapache2.conf make sure you have this:

```
UseCanonicalName Off
```

Also in commonapache2.conf, around line #771, change:

```
<Directory /var/www/localhost/htdocs>
```

to:

```
<Directory /var/www>
```

What this does is look in /var/www for a folder named <yourwebsite.com>.  If apache gets a request for www.yourwebsite.com, it uses the document root of /var/www/www.yourwebsite.com.  If the request is for mail.yourwebsite.com, apache will point the request to document root /var/www/mail.yourwebsite.com.  If said document root doesn't exist, it points it to /var/www/default.

Read the definition of UseCanonicalName option in commonapache2.conf it should explain things a bit better.

----------

## RedDawn

 *Shiner_Man wrote:*   

>  *RedDawn wrote:*   
> 
> YES YOU CAN!! THAT HOW I DO IT!1
> 
> http://mail.yourowndisaster.net   <-- it automatically send you to HTTPs
> ...

 

Sorry..  i forgot.. about this..

on top of the vhost file.. you shlould see the

Listen:80  or somthing like that..

copy the line down and instead of saying 80  ir should say 443 <--ssl

so

Listen 80

Listen 443

that should take care of the 

[warn] _default_ VirtualHost overlap on port 443, the first has precedence

make sure everything else is correct it works for me..

http://mail.yourowndisaster.net

----------

