Не удается получить доступ к сертификату letsencrypt, в то время как сертификаты могут редактироваться текущим пользователем - PullRequest
1 голос
/ 02 мая 2019

У меня ошибка, говорящая о том, что EACCES: permission denied, open '/etc/letsencrypt/live/example.com/privkey.pem', в то время как этот файл может быть доступен и изменен текущим пользователем, которого я использую при запуске проекта nodejs.Я делаю ответ здесь , и он позволяет мне получить доступ к этому файлу, но у меня все еще есть эта ошибка, когда я запускаю свой код на pm2, что здесь не так?

Моя ошибка говорит, что

{ Error: EACCES: permission denied, open 
    '/etc/letsencrypt/live/example.com/privkey.pem'
    at Object.openSync (fs.js:438:3)
    at Object.readFileSync (fs.js:343:35)
    at Object.<anonymous> (/home/samsung/projects/samsunggalaxy/galaxy/dist/index.js:126:17)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function._load (/usr/lib/node_modules/pm2/node_modules/@pm2/io/build/main/metrics/httpMetrics.js:172:43)
    at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:27:21)
    at Module._compile (internal/modules/cjs/loader.js:701:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
    at Module.load (internal/modules/cjs/loader.js:600:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:539:12)
    at Function.Module._load (internal/modules/cjs/loader.js:531:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:754:12)
  errno: -13,
  syscall: 'open',
  code: 'EACCES',
  path: '/etc/letsencrypt/live/example.com/privkey.pem' }

Хотя мой код при чтении файла с использованием nodejs был

import https from 'https';
import { priv_key, cert} from './custom/certs';
const fs = require('fs');
const socket = require('socket.io');

const option = {
    key: fs.readFileSync(priv_key), // '/etc/letsencrypt/live/example.com/privkey.pem'
    cert: fs.readFileSync(cert), // '/etc/letsencrypt/live/example.com/cert.pem'
    requestCert: false,
    rejectUnauthorized: false,
};

option.agent = new https.Agent(option);

const httpsServer = https.createServer(option, app);
const httpsIo = socket.listen(httpsServer)
httpsServer.listen(3005, () => {
    console.log(`started on port ${httpsServer.address().port}`);
});
...