Mobile app version of vmapp.org
Login or Join
Annie201

: Enabling 000-default.conf breaks namebased vhost I have two sites on a server: dev.somedomain.com and somedomain.com - the latter has a ServerAlias of *.somedomain.com. All domains are SSL-enabled,

@Annie201

Posted in: #Apache2 #Vhost

I have two sites on a server: dev.somedomain.com and somedomain.com - the latter has a ServerAlias of *.somedomain.com. All domains are SSL-enabled, and all requests to port 80 is redirected to https. The somedomain.com site is a proxy of an old site, on a different server, that is about to be decommisioned.

dev.somedomain.com works like a charm
somedomain.com is for some reason "caught" by the 000-default.conf configuration (https is not), but www.somedomain.com (the serveralias *.somedomain.com) is NOT "caught" by 000-default.conf, and is working as expected.

If I disable the 000-default.conf, everything seems to work, except for dev.somedomain.com/phpmyadmin (which DOES work with 000-default enabled - I think I understand why)

I've searched high and low, but been unable to figure this out.

somedomain.conf:

<VirtualHost *:80>
ServerName dev.somedomain.com

Redirect 301 / dev.somedomain.com </VirtualHost>

<VirtualHost *:80>
ServerName somedomain.com
ServerAlias *.somedomain.com

Redirect 302 / somedomain.com/ </VirtualHost>


And the 000-default.conf, which seems to break somedomain.conf:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>


somedomain-ssl.conf: (this one does not seem to have any problems, but included here to be sure)

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName dev.somedomain.com

DocumentRoot "/var/www/somedomain/wwwroot"
Alias /phpmyadmin /usr/share/phpmyadmin
Alias /index.php /var/www/somedomain/index.php
Alias /import-data.php /var/www/somedomain/import.php
<Directory /var/www/somedomain/wwwroot>
Options FollowSymLinks
AllowOverride None

Require all granted

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url= [QSA]
</Directory>

ErrorLog /var/www/somedomain/logs/error.log
CustomLog /var/www/somedomain/logs/access.log combined

ProxyPassMatch ^/(.*.php(/.*)?)$ unix:/run/php/php7.0-fpm.sock|fcgi://localhost/var/www/somedomain/

SSLCertificateFile /etc/letsencrypt/live/dev.somedomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/dev.somedomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

<VirtualHost *:443>
ServerName somedomain.com

<Location "/">
ProxyPreserveHost On

#anonymised IP to protect the guilty:
ProxyPass 172.0.0.10/ ProxyPassReverse somedomain.com/
AddOutputFilterByType INFLATE;SUBSTITUTE;DEFLATE text/html
Substitute "s somedomain.com/ /|iq"
SetOutputFilter DEFLATE
</Location>

SSLCertificateFile /etc/letsencrypt/live/dev.somedomain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/dev.somedomain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>


Long question short: why does somedomain.com show apaches default page, while www.somedomain.com is - as expected - redirected to somedomain.com?
I assume the answer is obvious, and I'm just blind, but I really have no idea what's going on.

Thank you

EDIT

VirtualHost configuration:
*:443 is a NameVirtualHost
default server dev.somedomain.com (/etc/apache2/sites-enabled/somedomain-ssl.conf:2)
port 443 namevhost dev.somedomain.com (/etc/apache2/sites-enabled/somedomain-ssl.conf:2)
port 443 namevhost somedomain.com (/etc/apache2/sites-enabled/somedomain-ssl.conf:35)
*:80 is a NameVirtualHost
default server somedomain.com (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost somedomain.com (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost dev.somedomain.com (/etc/apache2/sites-enabled/somedomain.conf:1)
port 80 namevhost somedomain.com (/etc/apache2/sites-enabled/somedomain.conf:7)
wild alias *.somedomain.com

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Annie201

1 Comments

Sorted by latest first Latest Oldest Best

 

@Moriarity557

First start with the output of the command apachectl -S. It shows you all your virtual hosts and the files they come from.

The first listed virtual host in the output is the 'default virtual host'. I am guessing this is the one in 000-default.conf. If so, then that virtual host has no ServerName and so will take the one from the global (server) context, or the hostname of the machine. If this is 'somedomain.com' then it means requests for this domain will land on this virtual host. If is is not the show us the output of apachectl -S to help troubleshoot.

Explanation: This is just the way virtual hosts work. Apachae tries to match the hostname used (actually the contents of the 'Host' HTTP header) against any ServerName or ServerAlias and once it finds a match that virtual host receives the request. If no match is found the first virtual host listed is used. So if you have two virtual host with the same ServerName only the first will can be accessed using that name.

Best practise: Give every virtual host a ServerName to make sure you explicitly know which requests will land on each one, and every time you make a configuration change run apachectl -S

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme