Dabeliuteef Dabeliuteef - 4 years ago 125
Apache Configuration Question

Apache same domain multi virtual host

I'm currently trying to set my Apache configuration.
I have one IP (ex:
) and one domain (ex:

This server is currently hosting 2 sites and each site has his own Apache Instance with his own conf and php.ini :

=> Site 1

=> Site 2

project1.conf is set like that (same with 443 for SSL) :

DocumentRoot /appli/projects/project1/apache_2.4/htdocs/project1folder/
ServerName mydomain.com

project2.conf is set like that (same with 453 for SSL) :

DocumentRoot /appli/projects/project2/apache_2.4/htdocs/project2folder/
ServerName mydomain.com

So when I am connecting to "mydomain.com" I am going to "Site 1" but I have to hit mydomain.com:453 for accessing to "Site 2" which is not really good...

I would like to have something like that :

=> "Site 1" (or

=> "Site 2" (or

And I would like to keep the
hitting the "Site 1".

Unfortunatly, because each site has his own instance of Apache, I have no idea how to set them.

Last but not the Least I would like to know if it's possible to share PHP (Apache)
accross the multi Apache Instance or if I have to use
accross the domain to share informations between sites.

I don't know if it's really clear, just ask if you need more informations.

Thanks you in advance.

Answer Source

My recommendation is this:

File structure:


Apache vhost:

    DocumentRoot /appli/projects/project1/apache_2.4/htdocs/
    ServerName  example.com

...and then do the same thing for the SSL-vhost.

Now you can use http://example.com/site1 and http://example.com/site2 and the same for https.

If you start using different ports (anything other than the defaults 80 and 443, you need to explicitly write the port names to be able to access the sites, or set up a reverse proxy (adds extra complexity with no real gain).

You can even define specific rules for site1 and site2 in your vhost.

Config per site:

    DocumentRoot /appli/projects/project1/apache_2.4/htdocs/
    ServerName  example.com

    <Directory /appli/projects/project1/apache_2.4/htdocs/site1/>
        # Some specific vhost config...

    <Directory /appli/projects/project1/apache_2.4/htdocs/site2/>
        # Some specific vhost config...


If you want different sub domains like: site1.example.com and site2.example.com, then just do different vhosts that point to the folders directly, still using port 80 for http and port 443 for https.

Just remember that you then need to have a multi-domain-certificate or a wildcard certificate for https (since they are two different hostnames). Or you could install Let's Encrypt.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download