在Jailkit中设置nodejs和npm

时间:2016-06-21 16:23:25

标签: node.js ubuntu npm chroot jail-shell

我在我的服务器上使用jailkit,我想在chrooted环境中添加对nodejs和npm的支持。我不知道我是否遗漏了一些我需要链接到我的jail,或者一些lib或二进制文件的目录,但我很遗憾。我将以下内容添加到jk_init.ini:

[node]
comment = NodeJS
executables = /usr/bin/npm, /usr/bin/node, /usr/bin/nodejs
directories = /usr/local/lib/node_modules

如果我从root用户运行npm ls,它运行正常。如果我尝试从我的jailed环境运行它,我会收到此错误:

npm ERR! Linux 3.16.0-28-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "ls"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! code MODULE_NOT_FOUND

npm ERR! Cannot find module 'ansi'
npm ERR! 
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /web/npm-debug.log

日志文件包含:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/nodejs', '/usr/bin/npm', 'ls' ]
2 info using npm@3.5.2
3 info using node@v4.2.6
4 verbose stack Error: Cannot find module 'ansi'
4 verbose stack     at Function.Module._resolveFilename (module.js:326:15)
4 verbose stack     at Function.Module._load (module.js:277:25)
4 verbose stack     at Module.require (module.js:354:17)
4 verbose stack     at require (internal/module.js:12:17)
4 verbose stack     at Object.<anonymous> (/usr/share/npm/lib/ls.js:15:13)
4 verbose stack     at Module._compile (module.js:410:26)
4 verbose stack     at Object.Module._extensions..js (module.js:417:10)
4 verbose stack     at Module.load (module.js:344:32)
4 verbose stack     at Function.Module._load (module.js:301:12)
4 verbose stack     at Module.require (module.js:354:17)
5 verbose cwd /web
6 error Linux 3.16.0-28-generic
7 error argv "/usr/bin/nodejs" "/usr/bin/npm" "ls"
8 error node v4.2.6
9 error npm  v3.5.2
10 error code MODULE_NOT_FOUND
11 error Cannot find module 'ansi'
12 error If you need help, you may report this error at:
12 error     <https://github.com/npm/npm/issues>
13 verbose exit [ 1, true ]

我正在使用ISPConfig运行最新版本的Ubuntu

2 个答案:

答案 0 :(得分:2)

今天也有问题,通过改变

修复它
directories = /usr/local/lib/node_modules 

directories = /usr/lib/node_modules

Debian Jessie,也是ISPConfig。

记得触发

jk_init -c /etc/jailkit/jk_init.ini -f -k -j /var/www/clients/clientX/web62 node

答案 1 :(得分:1)

别忘了添加环境可执行文件

[env]
comment = environment variables
executables = /usr/bin/env

[node]
comment = NodeJS
executables = /usr/bin/npm, /usr/bin/node, /usr/bin/nodejs
directories = /usr/lib/node_modules

jailkit chroot setup