问题描述
连接不安全
如何在XAMPP
中使用安全连接(SSL)?
解决方法
在我的XAMPP安装中,我基本上对我管理的所有站点都有一个克隆。而且所有这些(当然)都使用SSL / HTTPS。
这是分步指南:
在这一步中,我们将创建SSL
并设置“ site.test”网站。
1。导航到XAMPP中的Apache目录。
在常规安装中,它位于C:\ xampp \ apache中。
2。在该页面中创建一个文件夹。
这是我们将存储证书的地方。在此示例中,我将创建“ crt”文件夹。所以我们将有C:\xampp\apache\crt
3。添加此文件。
4。编辑cert.conf并运行make-cert.bat
使用我们要使用的域(在本例中为 site.test )保存并更改 {{DOMAIN}} 文本。
双击make-cert.bat并在出现提示时输入域site.test。只需输入其他问题,因为我们已经从cert.conf中设置了默认值。
注意:我不知道如何在.bat脚本中进行文本替换,如果您这样做,请在注释中让我知道如何进行操作,我将更新make-cert.bat用域输入自动替换{{DOMAIN}}。
5。在Windows中安装证书。
在那之后,您将看到site.test文件夹已创建。在该文件夹中,我们将具有 server.crt 和 server.key 。这是我们的SSL证书。
双击 server.crt 将其安装在Windows上,以便Windows可以信任它。
然后选择本地计算机作为存储位置。
然后选择“ 将所有证书放入以下商店”,然后单击浏览,然后选择“受信任的根证书颁发机构”。
点击下一步和完成。
现在Windows中已安装并信任此证书。接下来是如何在XAMPP中使用此证书。
6。在Windows主机中添加网站
- 以管理员身份打开记事本。
- 编辑
C:\Windows\System32\drivers\etc\hosts
(文件没有扩展名) - 在新行中添加:
127.0.0.1 site.test
这将告诉窗口在我们访问http://site.test
时加载 XAMPP 。您可以尝试一下,它将显示XAMPP仪表板页面。
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中的子目录。
8。重新启动浏览器并完成!
这是加载证书所必需的。并在浏览器上访问该域,您将看到绿色锁定!
我希望本教程对您有用!
来源:https://shellcreeper.com/how-to-create-valid-ssl-in-localhost-for-xampp/