如何在 localhost 中为 XAMPP 创建有效的 SSL [英] How to Create Valid SSL in localhost for XAMPP

查看:21
本文介绍了如何在 localhost 中为 XAMPP 创建有效的 SSL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

<块引用>

连接不安全

解决方案

在我的 XAMPP 安装中,我基本上对我管理的所有站点都有一个克隆.并且所有这些(当然)都使用 SSL/HTTPS.

这是分步指南:

在这一步中,我们将创建 SSL 并设置site.test"网站.

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

在常规安装中,它位于 C:xamppapache 中.

<强>2.在该页面中创建一个文件夹.

这是我们将存储我们的证书的地方.在本例中,我将创建crt"文件夹.所以我们会有 C:xamppapachecrt

3.添加此文件.

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

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

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

    <块引用>

    注意:我不知道如何在 .bat 脚本中进行文本替换,如果您知道,请在评论中告诉我如何操作,我会更新 make-cert.bat用域输入自动替换 {{DOMAIN}}.

    5.在 windows 中安装证书.

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

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

    然后选择 Local Machine 作为 Store Location.

    然后选择Place all certificate in the following store"并点击browse并选择Trusted Root Certification Authorities.

    点击下一步完成.

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

    6.在 Windows 主机中添加站点

    • 以管理员身份打开记事本.
    • 编辑C:WindowsSystem32driversetchosts(文件无分机)
    • 在新行中添加:

    127.0.0.1 site.test

    这将告诉窗口在我们访问 http://site.test 时加载 XAMPP 您可以尝试,它会显示 XAMPP 仪表板页面.

    7.在 XAMPP conf 中添加站点.

    我们需要为此域启用 SSL,并让 XAMPP 知道我们将 SSL 证书存储在哪里.所以我们需要编辑C:xamppapacheconfextrahttpd-xampp.conf

    并在底部添加此代码:

     ## site.test<虚拟主机 *:80>DocumentRoot "C:/xampp/htdocs"服务器名称 site.test服务器别名 *.site.test</虚拟主机><虚拟主机 *:443>DocumentRoot "C:/xampp/htdocs"服务器名称 site.test服务器别名 *.site.testSSLEngine 开启SSLCertificateFilecrt/site.test/server.crt"SSLCertificateKeyFilecrt/site.test/server.key"</虚拟主机>

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

    <块引用>

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

    8.重新启动浏览器并完成!

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

    希望本教程有用!

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

    How can I use a secure connection (SSL) in my XAMPP in windows?

    I get the following error when I open the localhost page:

    connection not secure

    解决方案

    In my XAMPP install I basically have a clone to all the site that I managed. And All of them (of course) use SSL/HTTPS.

    Here’s the step by step guide:

    In this step we are going to crate SSL and setup "site.test" website.

    1. Navigate to Apache directory in XAMPP.

    In regular install it’s in C:xamppapache.

    2. Create a folder in that page.

    This is where we will store our cert. In this example I will create "crt" folder. So we will have C:xamppapachecrt

    3. Add this files.

    4. Edit cert.conf and Run make-cert.bat

    Change {{DOMAIN}} text using the domain we want to use, in this case site.test and save.

    Double click the make-cert.bat and input the domain site.test when prompted. And just do enter in other question since we already set the default from cert.conf.

    Note: I don’t know how to do text replace in .bat script, if you do, let me know in the comment how to do it and I will update make-cert.bat to automatically replace the {{DOMAIN}} with the domain input.

    5. Install the cert in windows.

    After that, you will see site.test folder created. In that folder we will have server.crt and server.key. This is our SSL certificate.

    Double click on the server.crt to install it on Windows so Windows can trust it.

    And then select Local Machine as Store Location.

    And then Select "Place all certificate in the following store" and click browse and select Trusted Root Certification Authorities.

    Click Next and Finish.

    And now this cert is installed and trusted in Windows. Next is how how to use this cert in XAMPP.

    6. Add the site in Windows hosts

    • Open notepad as administrator.
    • Edit C:WindowsSystem32driversetchosts (the file have no ext)
    • Add this in a new line:

    127.0.0.1 site.test
    

    This will tell windows to load XAMPP when we visit http://site.test You can try and it will show XAMPP dashboard page.

    7. Add the site in XAMPP conf.

    We need to enable SSL for this domain and let XAMPP know where we store the SSL Cert. So we need to edit C:xamppapacheconfextrahttpd-xampp.conf

    And add this code at the bottom:

     ## 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>
    

    After that, you will need to restart Apache in XAMPP. It’s very simple, simply open XAMPP Control Panel and Stop and re-Start Apache Module.

    Tips: In XAMPP conf, as you can see you can change the domain root directory if needed. Eg. as sub-dir in htdocs.

    8. Restart your browser and Done!

    This is required to load the certificate. And visit the domain on your browser, and you will see green lock!

    I hope this tutorial is useful!

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

    这篇关于如何在 localhost 中为 XAMPP 创建有效的 SSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆