Reputation: 5844
I'm trying to configure a very basic server setup where domains are served from their own directory. For example:
https://oblik.dev/foo.html
> /var/www/oblik.dev/foo.html
https://test.oblik.dev/foo.html
> /var/www/test.oblik.dev/foo.html
I've enabled mod_vhost_alias and I have one VirtualHost in /etc/apache2/sites-available/main.conf
:
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/oblik.dev/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/oblik.dev/privkey.pem
UseCanonicalName Off
VirtualDocumentRoot /var/www/$0
ServerAlias *.dev
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
This is the output of apache2ctl -S
:
VirtualHost configuration:
*:443 46.101.237.154 (/etc/apache2/sites-enabled/main.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/run/apache2/" mechanism=default
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
Mutex ssl-stapling-refresh: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33
And here's the output of ls -al /var/www/
:
total 16
drwxr-xr-x 4 root root 4096 Mar 18 06:19 .
drwxr-xr-x 14 root root 4096 Mar 17 06:54 ..
drwxr-xr-x 2 www-data www-data 4096 Mar 17 09:30 ikarov.oblik.dev
drwxr-xr-x 2 www-data www-data 4096 Mar 18 07:14 oblik.dev
I have an index.php
in both directories with the same permissions as their folders.
When I open https://oblik.dev
, I get a 404. Same thing for https://ikarov.oblik.dev
. However, if I substitute VirtualDocumentRoot
for a regular DocumentRoot
, the server works as expected.
I know that Chrome handles .dev
domains a bit differently in that it enforces SSL, but I've set up an SSL certificate with wildcard domains via Let's Encrypt, so it shouldn't be a problem.
What am I missing?
Upvotes: 1
Views: 212
Reputation: 5844
The problem was that Apache uses %
for name interpolation instead of $
like Regex. I had to change this:
VirtualDocumentRoot /var/www/$0
...to this:
VirtualDocumentRoot /var/www/%0
Upvotes: 1