Apache2 Name Virtual host

Posted on 2005-05-12
Medium Priority
Last Modified: 2008-01-09
 I have an Apache2 web server on Debian.

I have two sites pointing to the same ip: www.mycompany.com and email.mycompany.com...

The email.mycomany.com is the webmail and runs using SSL certs.

My question is, how do I configure these Virtual hosts so that when I type email.mycompany.com into my browser it opens the secure webmail, but if I type www.mycompany.org it direct me to the default web page.

Thanks for your time

Question by:PastorDwayne

Expert Comment

ID: 13992359
Not sure how to achieve what you describe using a single IP (since you can't specify a port in DNS), but can suggest a more common alternative:

In DNS, point www.mycompany.com to your web server's IP.  On that site provide a http://www.mycompany.org/webmail page that redirects the user to https://your_webmail_virtual_host.  If you're running your secure webmail site on a non-standard port, say port 8088, your redirect would be to http://your_webmail_virtual_host:8088.

Expert Comment

ID: 13996803
apache does support NameBasedVirtualHost that is you can have more that one websites for an IP I hope you already knew that. The default www.mycompany.com can be configured without any issues right. for the second mail.mycompany.com put a php file or some thing that will redirect the request to https://mail.mycompany.com. You can also use apache's mod_rewrite to achive this but using php will be easier.


Accepted Solution

TimEliseo earned 600 total points
ID: 14001444
Here's the Apache configuration to do what you want. I do something very similar on one of my sites. I'm assuming you already have the two sites working separately and can plug in the appropriate config (and change the names and IP address, of course):



# The first entry is the default if ServerName doesn't match
    ServerName mycompany   # used for display only
    DocumentRoot /www/mycompany
    # ... more directives for regular web page

    ServerName email
    ServerAlias email.*
    Redirect permanent / "https:/www.mycompany.com/"

   SSLEngine on
   DocumentRoot /www/secure_webmail
  # ... more directives for secure webmail

I have no reason to think that doing this with PHP would be easier or more efficient. Note that if someone types a URL such as http://email.mycompany.com/SomePage.html it will be redirected to https://www.mycompany.com/SomePage.html. If you'd rather have all URLs in the email.mycompany.com domain get redirected to https://www.mycompany.com/ then change the redirect directive to:

   RedirectMatch permanent .* "https:/www.mycompany.com/"

Hope this helps,


Author Comment

ID: 14011074

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

755 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question