Solved

Apache2 VirtualHost config

Posted on 2009-04-06
2
445 Views
Last Modified: 2012-08-14
Apache2 listens on wo ports. 80 and 443.

We have one .mobi domain that needs to run on port 80. (The first virtual directory).

All other traffic on port 80 needs to be redirected to a specific domain on port 443. (2nd and 3rd virtual directories respectively).

Basically the first virtual directory doesn't seem to work correctly because even the .mobi domain is being redirected to the domain running on port 443.
<VirtualHost www.domainname.mobi:80>
	ServerAdmin info@domainname.co.za
	ServerName www.domainname.mobi
	ServerAlias domainname.mobi www.domainname.mobi
	DocumentRoot /wwwroot/domainname/www/
	DirectoryIndex m.index.php index.php
	<Directory />
		Options -Indexes
		AllowOverride All
		Order allow,deny
		allow from all
	</Directory>
 
	ErrorLog /var/log/apache2/error.log
 
	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn
 
	CustomLog /var/log/apache2/access.log combined
	ServerSignature Off
 
</VirtualHost>
<VirtualHost 196.***.***.***:80>
	ServerAdmin info@xpandit.co.za
	ServerName www.domainname.co.za
	DocumentRoot /wwwroot/domainname/www/
	<Directory />
		Options -Indexes
		AllowOverride All
		Order allow,deny
		allow from all
	</Directory>
 
	ErrorLog /var/log/apache2/error.log
 
	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn
 
	CustomLog /var/log/apache2/access.log combined
	ServerSignature Off
	RewriteEngine on
	RewriteCond %{SERVER_PORT}      !^443$
	RewriteRule ^/(.*)              https://www.domainname.co.za/$1 [R=301,L]
 
</VirtualHost>
<VirtualHost 196.***.***.***:443>
	ServerAdmin info@xpandit.co.za
	ServerName www.domainname.co.za
	DocumentRoot /wwwroot/domainname/www/
	SSLEngine on
	SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
	SSLProtocol -all +TLSv1 +SSLv3
	SSLCertificateFile /etc/ssl/certs/server.crt
	SSLCertificateKeyFile /etc/ssl/private/server.key	
	<Directory />
		Options -Indexes
		AllowOverride All
		Order allow,deny
		allow from all
	</Directory>
 
	ErrorLog /var/log/apache2/error.log
 
	# Possible values include: debug, info, notice, warn, error, crit,
	# alert, emerg.
	LogLevel warn
 
	CustomLog /var/log/apache2/access.log combined
	ServerSignature Off
 
</VirtualHost>

Open in new window

0
Comment
Question by:xpandit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
caterham_www earned 500 total points
ID: 24085113
Do youi have more then one IP adress? If not, use name-based virtual hosts for port 80, not IP-based:
NameVirtualhost *:80
<VirtualHost *:80>
        ServerAdmin info@xpandit.co.za
        ServerName www.domainname.co.za
        DocumentRoot /wwwroot/domainname/www/
        <Directory />
                Options -Indexes
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
 
        ErrorLog /var/log/apache2/error.log
 
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
 
        CustomLog /var/log/apache2/access.log combined
        ServerSignature Off
        # Keep it simple; no need for mod_reweite; the port is always 80
        Redirect 301 / https://www.domainname.co.za/
</VirtualHost>
<VirtualHost *:80>
        ServerAdmin info@domainname.co.za
        ServerName www.domainname.mobi
        ServerAlias domainname.mobi www.domainname.mobi
        DocumentRoot /wwwroot/domainname/www/
        DirectoryIndex m.index.php index.php
        <Directory />
                Options -Indexes
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
 
        ErrorLog /var/log/apache2/error.log
 
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
 
        CustomLog /var/log/apache2/access.log combined
        ServerSignature Off
</VirtualHost>
 
<VirtualHost 196.***.***.***:443>
        ServerAdmin info@xpandit.co.za
        ServerName www.domainname.co.za
        DocumentRoot /wwwroot/domainname/www/
        SSLEngine on
        SSLOptions +FakeBasicAuth +ExportCertData +StrictRequire
        SSLProtocol -all +TLSv1 +SSLv3
        SSLCertificateFile /etc/ssl/certs/server.crt
        SSLCertificateKeyFile /etc/ssl/private/server.key       
        <Directory />
                Options -Indexes
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
 
        ErrorLog /var/log/apache2/error.log
 
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
 
        CustomLog /var/log/apache2/access.log combined
        ServerSignature Off
 
</VirtualHost>

Open in new window

0
 

Author Closing Comment

by:xpandit
ID: 31567377
Perfect. Thank you.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

752 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