Windows環境下vscode Live Server插件如何開啟https


0x01 vscode http插件 Live Server如何開啟https

在本機端的開發環境下,如果要測試一些需要HTTPS的功能可以使用mkcert給自己頒發憑證

 

 

0x02 安裝步驟如下:

1、安裝 mkcert

安裝環境:Windows 7+ / Windows Server 2003+

1)以管理員身份運行powershell

2)執行命令: Get-ExecutionPolicy,如果系統返回 Restricted,則在執行命令:Set-ExecutionPolicy AllSigned ,選擇 A(全是)

3)執行命令:

Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

4)等待數秒,安裝完成

5)執行choco -?驗證是否安裝成功 

     具體詳細安裝方法見:https://chocolatey.org/install

     安裝完成后,執行命令 choco install mkcert,等待安裝完成。

 

2、安裝本地CA

將本地CA 加入系統的信任清單內:

執行命令  mkcert -install 

顯示下面結果,安裝完成

Created a new local CA at "C:\Users\**\AppData\Local\mkcert" 💥 The local CA is now installed in the system trust store! ⚡️

 

3、生成憑證

 

mkcert example.com "*.example.com" example.test localhost 127.0.0.1 ::1

返回:

Using the local CA at "C:\Users\**\AppData\Local\mkcert" ✨ Created a new certificate valid for the following names 📜(對應以下信任域名) - "example.com"
 - "*.example.com"
 - "example.test"
 - "localhost"
 - "127.0.0.1"
 - "::1" Reminder: X.509 wildcards only go one level deep, so this won't match a.b.example.com ℹ️ The certificate is at "./example.com+5.pem" and the key at "./example.com+5-key.pem"

在當前文件夾內生成2個文件:

example.com+5.pem 和 example.com+5-key.pem
分別是證書文件和私鑰

4、設置live server

開啟 settings.json 配置文件,輸入以下內容,並將cert, key 的路徑修改為剛剛創建的文件路徑

 

"liveServer.settings.https": { "enable": false, //set it true to enable the feature. "cert": "D:\\https\\example.com+5.pem", //full path "key": "D:\\https\\example.com+5-key.pem", //full path "passphrase": "" },

 

具體參考:https://github.com/ritwickdey/vscode-live-server/blob/master/docs/settings.md

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM