xfscrypt
xfscrypt

Reputation: 276

Apache: How to have multiple sites for one ServerName?

I have a site testing.mycompany.com/api and testing.mycompany.com/web. How do I configure this in apache?

<VirtualHost *:80>

        ServerName testing.somedomain.com
        ServerAlias testing.somedomain.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/project-2/

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>


<VirtualHost *:80>

        ServerName testing.mycompany.com/api
        ServerAlias testing.mycompany.com/api

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/project-1/

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

The moment I configure it as above, there will be a fallback to the first virtual host (testing.somedomain.com).

When I remove the /api, then it works. However I want configure another virtual host with /web. How can I accomplish this? Apparently ServerName doesn't allow paths after the root url?

Upvotes: 0

Views: 48

Answers (1)

Joao  Vitorino
Joao Vitorino

Reputation: 3256

testing.mycompany.com is the ServerName

/api and /web are Alias or Location.

If /api and /web are outside of your document root, you must use Alias.

Ex:

Document root of testing.mycompany.com = /var/www/

/api is a html page in /opt/myapi

/web is php page in /opt/web

So, inside your serverName you want 2 Alias.

<VirtualHost *:80>

        ServerName testing.mycompany.com
        ServerAlias testing.mycompany.com

        Alias /api /path/to/folder/where/is/api/files
        Alias /web /path/to/folder/where/is/web/files

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/project-1/

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Upvotes: 1

Related Questions