Solved

Apache2 VirtualHost config

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
local dns 2 137
Apache Virtual Hosts in Ubuntu 16.04 ignoring config for non SSL traffic 9 40
htaccess file errors for 301 Redirect 4 73
Guacamole and browser performance 1 64
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

861 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

22 Experts available now in Live!

Get 1:1 Help Now