I have a server with three vhosts, the default (domain.com), site1.com and site2.com. The server is running Ubuntu 22.04 LTS with Apache2. Until yesterday, this server only served the default domain, a simple hand-crafted site, and site1.com, which contains a Wordpress site, and did so without problems. I'm using HTTPS with LetsEncrypt certificates.
Yesterday, I installed site2.com and popped a second Wordpress instance there. Now, site1.com and domain.com work properly, but site2.com opens site1.com except when I type www.site2.com. Just typing site2.com opens site1.com.
I'm thoroughly confused. Can anyone suggest what's going wrong?
Here are my vhost files:
000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
000-default-le-ssl.conf
<IfModule mod_ssl.c>
SSLStaplingCache shmcb:/var/run/apache2/stapling_cache(128000)
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ServerName domain.com
SSLCertificateFile /etc/letsencrypt/live/domain.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/domain.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
Header always set Strict-Transport-Security "max-age=31536000"
SSLUseStapling on
</VirtualHost>
</IfModule>
site1.conf
<VirtualHost *:80>
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot "/var/www/site1.com/"
ErrorLog "/var/log/apache2/site1_com_error_log"
TransferLog "/var/log/apache2/site1_com__access_log"
<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =site1.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Site1-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot "/var/www/site1.com/"
ErrorLog "/var/log/apache2/site1_com_error_log"
TransferLog "/var/log/apache2/site1_com__access_log"
<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteCond %{SERVER_NAME} =site1.com
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/site1.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/site1.com/privkey.pem
</VirtualHost>
</IfModule>
Site2.conf
<VirtualHost *:80>
ServerName site2.com
ServerAlias www.site2.com
DocumentRoot "/var/www/site2.com/"
ErrorLog "/var/log/apache2/site2_com_error_log"
TransferLog "/var/log/apache2/site2_com_access_log"
<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =site2.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Site2-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName site2.com
ServerAlias www.site2.com
DocumentRoot "/var/www/site2.com/"
ErrorLog "/var/log/apache2/site2_com_error_log"
TransferLog "/var/log/apache2/site2_com_access_log"
<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
RewriteEngine on
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/site2.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/site2.com/privkey.pem
</VirtualHost>
</IfModule>
I have the following in my hosts file:
127.0.0.1 localhost
127.0.0.1 site1.com
127.0.0.1 site2.com
127.0.0.1 domain.com