我有两个不同的网站
domain1.com
domain2.com
问题:我只能通过 www.domain2.com 访问 domain2.com
如果我尝试 domain2.com,它会重定向到 domain1.com。
配置文件:
域名1.com.conf
<VirtualHost *:80> ServerName domain1.com ServerAlias www.domain1.com DocumentRoot /var/www/html </VirtualHost> <IfModule mod_ssl.c> <VirtualHost *:443> DocumentRoot /var/www/html ServerName www.domain1.com Include /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile /etc/letsencrypt/live/domain1.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/domain1.com/privkey.pem </VirtualHost> </IfModule>
域名2.com.conf
<VirtualHost *:80> ServerName domain2.com ServerAlias www.domain2.com DocumentRoot /var/www/public_html/domain2.com/wordpress </VirtualHost> <IfModule mod_ssl.c> <VirtualHost *:443> ServerAdmin [email protected] DocumentRoot /var/www/public_html/domain2.com/wordpress ServerName www.domain2.com Include /etc/letsencrypt/options-ssl-apache.conf SSLCertificateFile /etc/letsencrypt/live/domain2.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/domain2.com/privkey.pem </VirtualHost> </IfModule>
两个网站均有 .htaccess
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
命令certbot certificates
返回:
证书名称:domain1.com
域:domain1.com www.domain1.com
证书路径:/etc/letsencrypt/live/domain1.com/fullchain.pem
私钥路径:/etc/letsencrypt/live/domain1.com/privkey.pem证书名称:domain2.com
域:domain2.com www.domain2.com
证书路径:/etc/letsencrypt/live/domain2.com/fullchain.pem
私钥路径:/etc/letsencrypt/live/domain2.com/privkey.pem
答案1
对于端口 80 的 vHost 您有:
ServerName domain2.com
ServerAlias www.domain2.com
但对于端口 443,您只有:
ServerName www.domain2.com
(这适用于域 1 和域 2。)
因此如果您访问,https://domain2.com
它将被默认的 vHost 捕获(即第一个定义的www.domain1.com
:)
您还应该考虑重定向到端口 80 vHost 中的 HTTPS(规范)域。