我已经使用mkcert使用有效的HTTPS / SSL证书(Windows 10 XAMPP和Linux Debian 10 Apache2)创建无限* .dev.net子域和localhost。
我在Windows上使用mkcert v1.4.0创建证书(以管理员身份执行CMD):
mkcert -install
mkcert localhost "*.dev.net"
在Windows 10中创建此文件(我将首先在Windows 10 XAMPP中安装它)
localhost+1.pem
localhost+1-key.pem
覆盖XAMPP默认证书:
copy "localhost+1.pem" C:\xampp\apache\conf\ssl.crt\server.crt
copy "localhost+1-key.pem" C:\xampp\apache\conf\ssl.key\server.key
现在,在Apache2 for Debian 10中,激活SSL和vhost_alias
a2enmod vhosts_alias
a2enmod ssl
a2ensite default-ssl
systemctl restart apache2
对于vhost_alias,添加以下Apache2配置:
nano /etc/apache2/sites-available/999-vhosts_alias.conf
具有以下内容:
<VirtualHost *:80>
UseCanonicalName Off
ServerAlias *.dev.net
VirtualDocumentRoot "/var/www/html/%0/"
</VirtualHost>
添加站点:
a2ensite 999-vhosts_alias
通过SSH将证书复制到/ root / mkcert,并覆盖Debian的证书:
systemctl stop apache2
mv /etc/ssl/certs/ssl-cert-snakeoil.pem /etc/ssl/certs/ssl-cert-snakeoil.pem.bak
mv /etc/ssl/private/ssl-cert-snakeoil.key /etc/ssl/private/ssl-cert-snakeoil.key.bak
cp "localhost+1.pem" /etc/ssl/certs/ssl-cert-snakeoil.pem
cp "localhost+1-key.pem" /etc/ssl/private/ssl-cert-snakeoil.key
chown root:ssl-cert /etc/ssl/private/ssl-cert-snakeoil.key
chmod 640 /etc/ssl/private/ssl-cert-snakeoil.key
systemctl start apache2
编辑SSL配置
nano /etc/apache2/sites-enabled/default-ssl.conf
首先,编辑具有以下内容的文件:
<IfModule mod_ssl.c>
<VirtualHost *:443>
UseCanonicalName Off
ServerAlias *.dev.net
ServerAdmin webmaster@localhost
# DocumentRoot /var/www/html/
VirtualDocumentRoot /var/www/html/%0/
...
上次重启:
systemctl restart apache2
注意:不要忘记在/ var / www / html /中为您的子域创建文件夹。
/var/www/html/subdomain1.dev.net
/var/www/html/subdomain2.dev.net
/var/www/html/subdomain3.dev.net
sudo a2enmod rewrite
这将停止任何configtest / apache2配置错误。(如果您使用上面提供的虚拟主机添加,则会收到一个库存设置)