running multiple sites with a vhost

running multiple sites with a vhost

by Mitchell van Gerwen -
Number of replies: 3

Hello,

I wan't to run two sites on one server. I am using Moodle 2.4.1 with Centos 6.3 and apache as webserver. I have created a virtual host file, the file contains:

<VirtualHost *:80>
    ServerAdmin elobeheerder@ictmbo.nl
    DocumentRoot /var/www/html/mme
    Directory  /var/www/html/mme
    ServerName mme.ictmbo.nl
    ErrorLog logs/mme-error_log
    CustomLog logs/mme-access_log common
</VirtualHost>

The other domain name is elo.ictmbo.nl. The elo.ictmbo.nl config is stored in httpd.conf.

But when I restart apache. apache accepts the configuration. but when I enter elo.ictmbo.nl moodle is nagging that only the following url is allowed mme.ictmbo.nl. or when elo.ictmbo.nl is accepted, but mme.ictmbo.nl is not accepted. This depends on in which direction the wind is blowing.

I don't know what is happening. but I have two folders where the www data is stored in. and I have a different mysql database for each website.

Does anyone knows what I am doing wrong, of have someone a better idea to hosts two or more Moodle sites?  Thanks in advance!!!!

Average of ratings: -
In reply to Mitchell van Gerwen

Re: running multiple sites with a vhost

by chris dennison -

Your vhost statement <VirtualHost *.80> is telling Apache to listen and respond to any requests arriving at the host IP address, regardless of the requested url.  Moodle checks to see if the client's requested address matches the current moodle url and complains if they are different.  I believe you need two unique virtual host statements, one for each domain.

In reply to Mitchell van Gerwen

Re: running multiple sites with a vhost

by Ken Task -
Picture of Particularly helpful Moodlers

For official docs on virtual hosting with apache:

https://httpd.apache.org/docs/2.2/vhosts/name-based.html

Main host goes away

If you are adding virtual hosts to an existing web server, you must also create a <VirtualHost> block for the existing host. The ServerName and DocumentRoot included in this virtual host should be the same as the global ServerName and DocumentRoot. List this virtual host first in the configuration file so that it will act as the default host.


Some other settings in httpd.conf (the main config for Apache) to check:

# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, in addition to the default. See also the <VirtualHost>
# directive.
Listen 80

### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.2/vhosts/>;
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.

#
# Use name-based virtual hosting.
# note ... this item is initially commented out
NameVirtualHost *:80

You said the 'other server' is in httpd.conf' …
could we have a look see?

As far as each Moodle config ... it's 'strict' and must match that of the virtual server config.

'spirit of sharing', Ken