This content originally appeared on DEV Community and was authored by AXUM中文博客
自签证书
我们将使用 openssl 来自签证书,请确保你已安装了该工具。
自签IP证书
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout <私钥路径>.key -out ./<证书路径>.crt -subj '/CN=<组织名称>' -addext 'subjectAltName=IP:<局域网IP地址>'
-
<私钥路径>
:要保存私钥的路径 -
<证书路径>
:要保存证书的路径 -
<组织名称>
:签发证书的组织的名称 -
<局域网IP地址>
:本机IP地址
举例:
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout ./oneplus.key -out ./oneplus.crt -subj '/CN=ONEPLUS' -addext 'subjectAltName=IP:192.168.1.13'
自签“域名”证书
和 IP 证书类似,自签“域名”证书的唯一不同的是 subjectAltName
要修改为 DNS:<域名>
:
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout <私钥路径>.key -out <证书路径>.crt -subj '/CN=<组织名称>' -addext 'subjectAltName=DNS:<域名>'
-
<域名>
:绑定到该局域网的域名。通常,我们可以在客户机上修改 hosts 文件进行绑定。
举例:
openssl req -x509 -newkey rsa:4096 -sha256 -days 3650 -nodes -keyout ./oneplus.key -out ./oneplus.crt -subj '/CN=ONEPLUS' -addext 'subjectAltName=DNS:oneplus.axum.rs'
修改 hosts
- Linux/MacOS:
/etc/hosts
- Windows:
C:\Windows\System32\drivers\etc
在文件末尾加上:
<IP地址> <域名>
举例:
192.168.1.13 oneplus.axum.rs
Windows 安装根证书
将上一步骤生成的 .crt
文件通过 SFTP 等软件,复制到 Windows 中。然后双击该文件,点击安装,然后选择受信任的根证书颁发机构
即可
termux 中 proot-distro debian 的
root
用户的家目录位于:/data/data/com.termux/files/usr/var/lib/proot-distro/installed-rootfs/debian/root
Code Server 设置
修改 Code Server 配置文件:
// ...
cert: <证书路径>.crt
cert-key: <私钥路径>.key
举例:
// ...
cert: /root/.config/code-server/oneplus.crt
cert-key: /root/.config/code-server/oneplus.key
重启 Code Server。
This content originally appeared on DEV Community and was authored by AXUM中文博客

AXUM中文博客 | Sciencx (2025-01-03T01:24:18+00:00) 使用自签证书在局域网部署 HTTPS 并让浏览器识别为『安全』. Retrieved from https://www.scien.cx/2025/01/03/%e4%bd%bf%e7%94%a8%e8%87%aa%e7%ad%be%e8%af%81%e4%b9%a6%e5%9c%a8%e5%b1%80%e5%9f%9f%e7%bd%91%e9%83%a8%e7%bd%b2-https-%e5%b9%b6%e8%ae%a9%e6%b5%8f%e8%a7%88%e5%99%a8%e8%af%86%e5%88%ab%e4%b8%ba%e3%80%8e/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.