如何在本地主机中为 XAMPP 创建有效的 SSL [已关闭]

问题描述 投票:0回答:1

如何在 Windows 中的 XAMPP 中使用安全连接 (SSL)?

打开本地主机页面时出现以下错误:

连接不安全

windows ssl xampp
1个回答
94
投票

在我的 XAMPP 安装中,我基本上克隆了我管理的所有站点。 他们(当然)都使用 SSL/HTTPS。

enter image description here

这是分步指南:

在这一步中,我们将创建

SSL
并设置“site.test”网站。

enter image description here

1。导航到 XAMPP 中的 Apache 目录。

在常规安装中,它位于 C:\xampp pache 中。

enter image description here

2。在该页面中创建一个文件夹。

这是我们存储证书的地方。在此示例中,我将创建“crt”文件夹。所以我们会有

C:\xampp\apache\crt

enter image description here

3.添加此文件。

enter image description here

4。编辑 cert.conf 并运行 make-cert.bat

使用我们要使用的域更改 {{DOMAIN}} 文本,在本例中为 site.test 并保存。

双击 make-cert.bat 并在出现提示时输入域 site.test。只需输入其他问题即可,因为我们已经从 cert.conf 设置了默认值。

enter image description here

注意:我不知道如何在 .bat 脚本中进行文本替换,如果您这样做,请在评论中告诉我如何做,我将更新 make-cert.bat 以自动替换 {{DOMAIN }} 与域输入。

enter image description here

5。在 Windows 中安装证书。

之后,您将看到创建的 site.test 文件夹。在该文件夹中,我们将有 server.crtserver.key。这是我们的 SSL 证书。

双击 server.crt 将其安装在 Windows 上,以便 Windows 可以信任它。

enter image description here

然后选择本地计算机作为存储位置。

enter image description here

然后选择“将所有证书放入以下存储”,然后单击浏览并选择受信任的根证书颁发机构

enter image description here

单击下一步完成

现在该证书已在 Windows 中安装并受信任。接下来就是如何在XAMPP中使用这个证书了。

enter image description here

6。在 Windows 主机中添加站点

  • 以管理员身份打开记事本。
  • 编辑
    C:\Windows\System32\drivers\etc\hosts
    (文件没有扩展名)
  • 将其添加到新行中:
127.0.0.1 site.test

这将告诉 Windows 在我们访问时加载 XAMPP

http://site.test
您可以尝试,它将显示 XAMPP 仪表板页面。

enter image description here

7。在 XAMPP conf 中添加站点。

我们需要为此域启用 SSL,并让 XAMPP 知道我们存储 SSL 证书的位置。所以我们需要编辑

C:\xampp\apache\conf\extra\httpd-xampp.conf

并在底部添加此代码:

 ## site.test
 <VirtualHost *:80>
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
 </VirtualHost>
 <VirtualHost *:443>
     DocumentRoot "C:/xampp/htdocs"
     ServerName site.test
     ServerAlias *.site.test
     SSLEngine on
     SSLCertificateFile "crt/site.test/server.crt"
     SSLCertificateKeyFile "crt/site.test/server.key"
 </VirtualHost>

之后,您需要在 XAMPP 中重新启动 Apache。 非常简单,只需打开 XAMPP 控制面板并停止并重新启动 Apache 模块。

提示:在 XAMPP conf 中,如您所见,您可以根据需要更改域根目录。例如。作为 htdocs 中的子目录。

enter image description here

8。重新启动浏览器即可完成!

这是加载证书所必需的。然后在浏览器上访问该域名,你会看到绿色的锁!

enter image description here

enter image description here

我希望本教程有用!

来源:https://shellcreeper.com/how-to-create-valid-ssl-in-localhost-for-xampp/

© www.soinside.com 2019 - 2024. All rights reserved.