Solved

Apache2 VirtualHost config

Posted on 2009-04-06
2
439 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
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Join & Write a Comment

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now