I have multiple virtual hosts on port 80 and 443. They all work. The problem comes when addressing the web server by a name not mentioned as a vhost.
The documentation says:
If the lookup fails (the IP address wasn't found) the request is served from the default vhost if there is such a vhost for the port to which the client sent the request. If there is no matching default vhost the request is served from the main_server.
But in my case content is server from the main_server instead of the default vhost. I have tried using both _default_
and *
for this default vh
I have
NameVirtualHost *:80
NameVirtualHost *:443
And directives like:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
and
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
Running apachectl -S
Shows my carefully named default vhost.
wildcard NameVirtualHosts and _default_ servers:
*:443 is a NameVirtualHost
default server 00default.example.com (/etc/httpd/sites.d/00default.example.com:29)
port 443 namevhost 00default.example.com (/etc/httpd/sites.d/00default.example.com:29)
alias www.00default.example.com
port 443 namevhost example.com (/etc/httpd/sites.d/example.com:29)
alias www.example.com
...
*:80 is a NameVirtualHost
default server 00default.example.com (/etc/httpd/sites.d/00default.example.com:1)
port 80 namevhost 00default.example.com (/etc/httpd/sites.d/00default.example.com:1)
alias www.00default.example.com
port 80 namevhost example.com (/etc/httpd/sites.d/example.com:1)
alias www.example.com
If I visit
http://www.example.com/phpinfo/
It works fine. But
https://www.example.com/phpinfo/
Fails. This is because Apache attempts to serve this request from the document root configured for the main server in the default conf file. "Main server" is defined here: http://httpd.apache.org/docs/2.2/vhosts/details.html
www.example.com is the actual hostname of the server and
https://www/phpinfo/
or
https://ip.address/phpinfo/
Both work.
It's my understanding that a wildcard default vhost overrides the main server config as it is doing in the case of the HTTP version. Why does it not work for the HTTPS version?
Sample Vhost config:
<VirtualHost *:443>
ServerName example.com
ServerAlias www.example.com
ServerAdmin webmaster@localhost
DocumentRoot /var/www/example.com
#ErrorLog logs/example.com/error_log
#TransferLog logs/example.com/access_log
SSLEngine on
SSLCertificateFile /etc/httpd/certs.d/example.com.crt
SSLCertificateKeyFile /etc/httpd/certs.d/example.com.key
SSLCertificateChainFile /etc/httpd/certs.d/example.com.chain
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/example.com/>
AddType application/x-httpd-php .php
</Directory>
<Directory /var/www/example.com/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
There is also a section preceding the one above, for port 80, that is identical except for the port and the absence of the lines starting "SSL".