我正在尝试在我的 Windows 10 计算机上使用 Node.js 托管一个 HTTPS 网站,但 Node.js 突然无法读取我使用 Let's Encrypt's Certbot 获得的 fullchain.pem
。>
这是我的 Node.js 代码:
const fs = require("fs")
const https = require("https")
const FS_OPTIONS = {
encoding: "utf-8",
flag: "r",
}
const key = fs.readFileSync("C:/Certbot/live/subdomain.example.com/privkey.pem", FS_OPTIONS)
const cert = fs.readFileSync("C:/Certbot/live/subdomain.example.com/fullchain.pem", FS_OPTIONS)
https.createServer({ key, cert }, (req, res) => {
// do stuff...
}).listen(8888)
但是,当我运行它时,我收到以下错误:
Error: EPERM: operation not permitted, open 'C:/Certbot/live/subdomain.example.com/fullchain.pem'
at Object.openSync (fs.js:476:3)
at Object.readFileSync (fs.js:377:35)
at Object.<anonymous> (D:\Users\...\index.js:8:17)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47 {
errno: -4048,
syscall: 'open',
code: 'EPERM',
path: 'C:/Certbot/live/subdomain.example.com/fullchain.pem'
}
我可以绕过它的唯一方法是以管理员身份运行,但这很奇怪,因为以前不需要这样做。
如何将其恢复到以前的行为?
答案 0 :(得分:1)
您只需要更改以下文件夹及其子文件夹的访问权限:C:/Certbot
添加对运行 nodejs 的用户的访问权限。例如下面这个: https://v2cloud.com/tutorials/how-to-change-folder-permissions-on-windows-2016