我正在尝试将我的应用程序转换为 PWA,我需要在我的 raspberrypi 4 上的本地主机上使用 https,并且可以在 LAN 上使用 192.168.0.2 进行访问
\n证书似乎无效,我不明白我缺少什么。
\n所有命令均以root用户执行,所有步骤均来自GitHub官方页面
\nmkcert -install\n\nmkcert 192.168.80.2\nUsing the local CA at "/root/.local/share/mkcert" \xe2\x9c\xa8\n\nCreated a new certificate valid for the following names \xef\xbf\xbd\n - "192.168.0.2"\n\nThe certificate is at "./192.168.0.2.pem" and the key at "./192.168.0.2-key.pem" \xe2\x9c\x85\n\nmv 192.168.0.2-key.pem /etc/apache2/ssl/192.168.0.2-key.pem\nmv 192.168.0.2.pem /etc/apache2/ssl/192.168.0.2.pem\n\nls -l /etc/apache2/sites-enabled\nlrwxrwxrwx 1 root root 29 Jul 21 16:34 hiker.conf -> ../sites-available/hiker.conf\nRun Code Online (Sandbox Code Playgroud)\n可用站点/hiker.conf
\n<VirtualHost *:80>\n # The ServerName directive sets the request scheme, hostname and port that\n # the …Run Code Online (Sandbox Code Playgroud) 难以在与 WSL2 隔离的本地开发环境中安装证书。我在 macOS 和 Linux 中执行了完全相同的步骤,并且遇到了零问题。
步骤如下:
# Download and install mkcert
if [[ `uname` = "Darwin" ]] then
brew install mkcert
brew install nss
else
curl -Lo mkcert https://github.com/FiloSottile/mkcert/releases/download/v1.4.3/mkcert-v1.4.3-linux-amd64 && \
sudo install mkcert /usr/local/bin/
fi
# Installing tls certificate
mkcert -install
# Installing tls certificate
mkcert localhost 127.0.0.1 ::1
# Installing cert-manager locally
kubectl apply -f https://github.com/jetstack/cert-manager/releases/download/v1.2.0/cert-manager.yaml
# Add the certificates to secrets
kubectl create secret tls tls-localhost-dev --key=localhost+2-key.pem --cert=localhost+2.pem -n dev
# Create the tls service …Run Code Online (Sandbox Code Playgroud) ssl-certificate kubernetes windows-subsystem-for-linux cert-manager mkcert
我正在使用mkcert为本地主机生成自签名证书。
mkcert -install
mkcert localhost
Run Code Online (Sandbox Code Playgroud)
这对于浏览器来说效果很好,但是如果我尝试从节点获取数据,则会收到以下错误:
FetchError:请求 https://localhost:52882/ 失败,原因:无法验证第一个证书
我认为这是因为 mkcert 没有创建完整的链。
我已经通过使用环境变量解决了这个问题NODE_EXTRA_CA_CERTS。
NODE_EXTRA_CA_CERTS="$(mkcert -CAROOT)/rootCA.pem"
Run Code Online (Sandbox Code Playgroud)
我知道有process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";核方法,但我很想知道如果没有这些方法如何解决这个问题。
我正在尝试通过 https local 运行我的 React 应用程序。我已按照本教程的步骤进行操作,已正确安装mkcert,并且我的项目的根目录当前如下所示:
|-- my-react-app
|-- package.json
|-- localhost.pem
|-- localhost-key.pem
|--...
Run Code Online (Sandbox Code Playgroud)
我的 package.json 文件如下所示:
"scripts": {
"start": "HTTPS=true SSL_CRT_FILE=localhost.pem SSL_KEY_FILE=localhost-key.pem react-scripts start",
...
Run Code Online (Sandbox Code Playgroud)
然而,当我运行 npm start 时,我收到此错误:
'HTTPS' is not recognized as an internal or external command, operable program or batch file.
我还尝试在根目录中创建一个.env文件并添加如下变量:
HTTPS=true
SSL_CERT_FILE=localhost.pem
SSL_KEY_FILE=localhost-key.pem
Run Code Online (Sandbox Code Playgroud)
但是,当我以这种方式运行应用程序时,我收到一条警告,指出我的连接不安全。
我花了一些时间在谷歌上搜索错误,但到目前为止仍然无法找到解决方案。
mkcert ×4
ssl ×2
apache ×1
cert-manager ×1
https ×1
kubernetes ×1
linux ×1
localhost ×1
node.js ×1
reactjs ×1