I'm using Apache 2.4 on Ubuntu 16.04.
No matter what I do - can't make virtual hosts work, everything is routed to the configuration defined in 000-default.conf. I've got the following sites enabled:


<VirtualHost *.80>
    ServerName dev.example.com
    DocumentRoot "a valid path"
    ProxyPass /api http://localhost:8090
    ServerAdmin webmaster@example.com
    ProxyPreserveHost On
    RemoteIPHeader X-Forwarded-For
    RemoteIPInternalProxy localhost


<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    RewriteEngine on
    RewriteCond %{SERVER_NAME} =www.example.com [OR]
    RewriteCond %{SERVER_NAME} =example.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

Of course, the domain was changed to example.com and I removed the real file path for the document root.
Both files appear /etc/apache2/sites-enabled, and if add some garbage in dev.conf Apache doesn't start so I know it reads it.
The DNS is setup correctly - nslookup for dev.example.com and example.com return the same correct IP (tested from an external network).
I've had a similar setup with Debian and Apache 2.2, and it worked just fine (don't have it anymore, can't compare).

Any request I send is routed to 000-default.conf, dev.example.com or anything-that's-valid.example.com, since I don't have a DocumentRoot directive (I tried adding it as well) due to the fact that I'm redirecting to the https version, I'm getting the default /var/www/html.
This path does not appear in any config file and is probably compiled in as the default value for DocumentRoot.

Does anyone have an idea on how to make the dev.conf virtual host work?


You have a typo:

<VirtualHost *.80>

Should be

<VirtualHost *:80>
  • It happens to all of us. ;) – mzhaase Jan 25 '17 at 8:25

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.