Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different VirtualHosts with the same port

Tags:

I need to have two VirtualHosts with the same listen port for different projects and with different logs. Here's what I've got:

<VirtualHost *:80>
        DocumentRoot /home/projects/smk
        ErrorLog /var/log/apache2/smk-error.log
        RedirectMatch ^/$ /cms
</VirtualHost>

<VirtualHost *:80>
        DocumentRoot /home/projects/smk/cms
        ErrorLog /var/log/apache2/smk-cms-error.log
</VirtualHost>

<VirtualHost *:80>
        DocumentRoot /home/projects/smk/deploy
        ErrorLog /var/log/apache2/smk-deploy-error.log
</VirtualHost>
like image 738
ZiTAL Avatar asked May 20 '11 09:05

ZiTAL


People also ask

How do I change the default virtual host in Apache?

The solution is: # apache2. conf # @warning this is specific to apache 2.2 NameVirtualHost *:80 Listen 80 # ... In my case, to work, I created a VirtualHost (n.e. VirtualHost per CNAME ) called aaaa.


1 Answers

Add different ServerName directive in all virtual hosts:

<VirtualHost *:80>
        ServerName dev.localhost
        DocumentRoot /home/projects/smk/cms
        ErrorLog /var/log/apache2/smk-cms-error.log
</VirtualHost>

<VirtualHost *:80>
        ServerName my-project.localhost
        DocumentRoot /home/projects/smk/deploy
        ErrorLog /var/log/apache2/smk-deploy-error.log
</VirtualHost>

Don't forget to add host-entries for dev.localhost and my-project.localhost in /etc/hosts to 127.0.0.1 or whatever ip you want it to point to.

like image 117
Ashwini Dhekane Avatar answered Oct 01 '22 18:10

Ashwini Dhekane