Apache2- need multiple projects with same domain that use different path after domain name

4.8k views Asked by At

I have 2 completely different projects I would like to host from the same domain name "mysimpledomainname.com" with ip address xx.xx.xxx.xx (not local)

The 2 projects are located at Project 1) /var/www/html/project1 Project 2) /var/www/html/project2

I would like to have the 2 projects resolve like this

Project 1

mysimpledomainname.com

project 2

mysimpledomainname.com/project2

I DO NOT want to use subdomain names. This is for a project on my public server, not my local machine, so I don't think updating the host file will help me.

I already have the first project loading from mysimpledomainname.com (it's already working).

In the directory sites-available I have the conf file mysimpledomainname.com.conf with values:

<VirtualHost *:80>
        ServerAdmin [email protected]
        DocumentRoot /var/www/html/project1
        <Directory /var/www/html/project1/>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
                RewriteEngine On
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

I think I need to have 2 different conf files set up in order to do this, but after searching around I have not been able to find a solution. Can anyone help me with this? Rather than giving a short answer can you post exactly what I would need for the 2 different conf files?

Thanks,

David

1

There are 1 answers

2
Marki555 On BEST ANSWER

You can have only 1 VirtualHost directive as this is defined per FQDN and you want to use only mysimpledomainname.com.

Your config for Project1 is OK. You just need to make available another directory under path /project2. To do this, you need to use the Alias directive.

So your final config should be something like this (of course you can have separate Directory configurations for each subdir if you want):

<VirtualHost *:80>
        ServerAdmin [email protected]
        DocumentRoot    /var/www/html/project1
        Alias /project2 /var/www/html/project2
        <Directory /var/www/html/>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
                RewriteEngine On
        </Directory>
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>