0

system: ubuntu 14.04 as a VPS, apache 2.4.7

I have several virtual hosts set up, listening to :80 and :443 ports.

If I apache2ctl -S it shows incorrect virtual host as default on port 80. And indeed, if I browse to http://default.com, I get the content from another virtual host: the one Apache points as the default, but shouldn't be (customer.com). What is wrong in my setup?

My enabled-sites are :

default.com customer.com

apache2ctl -S

    VirtualHost configuration:
    *:80  is a NameVirtualHost
             default server customer.com (/etc/apache2/sites-enabled/customer.com.conf:1)
             port 80 namevhost customer.com (/etc/apache2/sites-enabled/customer.com.conf:1)
             port 80 namevhost www.customer.com (/etc/apache2/sites-enabled/customer.com.conf:19)
             port 80 namevhost www.default.com (/etc/apache2/sites-enabled/default.com.conf:36)
             port 80 namevhost tools.default.com (/etc/apache2/sites-enabled/default.com.conf:41)
             port 80 namevhost phpmyadmin.default.com (/etc/apache2/sites-enabled/default.com.conf:57)

    *:443  is a NameVirtualHost
             default server default.com (/etc/apache2/sites-enabled/customer.com.conf:26)
             port 443 namevhost default.com (/etc/apache2/sites-enabled/customer.com.conf:26)
             port 443 namevhost default.com (/etc/apache2/sites-enabled/default.com.conf:1)
             port 443 namevhost www.default.com (/etc/apache2/sites-enabled/default.com.conf:31)
             port 443 namevhost default.com (/etc/apache2/sites-enabled/default.conf:26)

default.com Vhost

    <VirtualHost *:443>
    ServerName default.com

    DocumentRoot /data/www/default.com/public
    <Directory /data/www/default.com/public>
        Require all granted
    </Directory>

    # SSL stuff ...

    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/data/www/default.com/public/$1

</VirtualHost>

<VirtualHost *:443>
     ServerName www.default.com
     RedirectMatch (.*) https://default.com$1
</VirtualHost>

<VirtualHost *:80>
     ServerName www.default.com
     RedirectMatch (.*) https://default.com$1
</VirtualHost>

<VirtualHost *:80>
    ServerName tools.default.com

    DocumentRoot /data/www/default.com/subdomains/tools/public

    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/data/www/default.com/subdomains/tools/public/$1

    <Directory /data/www/default.com/subdomains/tools/public>
        Require all granted
    </Directory>
    LogLevel error
</VirtualHost>

<VirtualHost *:80>
    ServerName phpmyadmin.default.com
    DocumentRoot /usr/share/phpmyadmin
    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/usr/share/phpmyadmin/$1

    <Directory /usr/share/phpmyadmin>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Customer.com vhost

<VirtualHost *:80>
    ServerName customer.com

    DocumentRoot /data/www/customer.com/public
    <Directory /data/www/customer.com/public>
        Require all granted
    </Directory>

    ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9001/data/www/customer.com/public/$1

</VirtualHost>

<VirtualHost *:80>
     ServerName www.customer.com
     RedirectMatch (.*) http://customer.com$1
</VirtualHost>
1

You don't have an entry for the non-www default.com

This should be added to the default.com config:

<VirtualHost *:80>
     ServerName default.com
     RedirectMatch (.*) https://default.com$1
</VirtualHost>
  • thank you, that corrected the issue. Still, apache2ctl -S shows incorrect default. Does it matter? – pixeline Feb 8 '15 at 16:29
  • Well, if everything works as it should I wouldn't put too much into what apache2ctl says :-) – Frederik Nielsen Feb 8 '15 at 16:30
  • Yeah, makes me nervous though. I'm setting up my first VPS for hosting professional projects, I hope my setup is futureproof... – pixeline Feb 8 '15 at 17:59
  • 1
    Update: I managed to fix that by controlling the loading order of all the vhost conf files. I simply renamed my default file from domain.com.conf to 000-domain.com.conf. reloaded Apache. apache2ctl -S now shows the correct default website for each port. Easy peasy. – pixeline Feb 12 '15 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.