You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# This is the default config file. It allows all users to do anything,# so don't use it on production systems.## Look here for more config file examples:# https://github.com/rlidwka/sinopia/tree/master/conf## path to a directory with all packages
storage: ./storage // npm包存放的路径
auth:
htpasswd:
file: ./htpasswd // 保存用户的账号密码等信息
# Maximum amount of users allowed to register, defaults to "+inf".# You can set this to -1 to disable registration.
max_users: -1 //默认为1000,改为-1,禁止注册
# a list of other known repositories we can talk to
uplinks:
npmjs:
url: http://registry.npmjs.org/ // 默认为npm的官网
packages: // 配置权限管理
'@*/*':
# scoped packages
access: $all
publish: $authenticated'*':
# allow all users (including non-authenticated users) to read and# publish all packages## you can specify usernames/groupnames (depending on your auth plugin)# and three keywords: "$all", "$anonymous", "$authenticated"
access: $all# allow all known users to publish packages# (anyone can register by default, remember?)
publish: $authenticated# if package is not available locally, proxy requests to 'npmjs' registry
proxy: npmjs
# log settings
logs:
- {type: stdout, format: pretty, level: http}
#- {type: file, path: sinopia.log, level: info}# you can specify listen address (or simply a port)
listen: localhost:4873 // 默认没有,只能在本机访问,把localhost改为0.0.0.0后可以通过外网访问
使用sinopia搭建私有npm服务
为什么需要搭建私有npm
为什么写这篇文章
写这边文章的时候,已经看到大神们写过的几篇不错的文章,这里想集中汇总一下,并且说明一下已有文章没有提到的坑
下面列举一下感觉不错的文章:
介绍sinopia
sinopia 的介绍与优缺点就不详细介绍了 上面2篇文章都有很详细的说明
部署安装和使用
安装 sinopia 与启动(假设你已经安装过node环境)
然后打开浏览器 访问地址
http://localhost:4873/
正常显示即成功,4873
是默认端口配置npm代理
sinopia启动之后,首先通过
npm set registry http://localhost:4873/
来设置客户端使用的npm代理,然后就能正常使用了添加用户与登录
登录成功之后,你就可以执行
npm publish
发布到这个私有npm上面啦,刷新http://localhost:4873/
就可以看到你刚刚上传的包啦。配置
Sinopia的特点是,你在哪个目录运行,它的就会在对应的目录下创建自己的文件。
在没有指定配置文件的情况下,默认目录是安装目录 你可以通过sinopia -c path/config.yaml 来指定目录运行
目录下默认有两个文件:config.yaml和storage ,htpasswd 是添加用户之后自动创建的。
config.yaml
:配置访问权限,代理,文件存储路径等所有配置信息的htpasswd 配置
config.yaml 中的 max_users: -1
表示我们将最大用户数设置为-1,表示禁用 npm adduser 命令来创建用户,不过仍然可以通过目录下的 htpasswd 文件来初始化用户, 打开 htpasswd 文件很明显密码被加密了,但是加密算法很简单,就是简单的 SHA1 哈稀之后再转换成 Base64,后面加上时间戳。
即使这样,我们还是很懵逼,还是不知道如何去添加用户?不要怕!! 这里给大家安利一个好用的小插件 htpasswd-for-sinopia, 没错,就是作者本人写的,大家觉得不错一定要赏颗
star
啊。下面简单介绍下 htpasswd-for-sinopia 的用法:packages配置(之前的文章这部分已经说的很详细了,这里直接copy过来)
配置大致分为两个部分,一个是以 @weflex/* 为开头的,另一个则是通配符 *。
这个当然就是对 package.json 中的 name 字段进行匹配,比如 @weflex/app 将匹配第一个配置,而 express 则匹配第二个。
这里这么配置的意义在于:一般团队或者公司的私有项目,会采用不同的权限控制,于是这里借用了 NPM 的 scoped name 即 @Company 的形式,例如 @weflex/app 即表示 WeFlex 下属的 app 项目了。
接下来,每一个命名过滤器(filter)下都有三项基本设置:
access: 表示哪一类用户可以对匹配的项目进行安装(install)
publish: 表示哪一类用户可以对匹配的项目进行发布(publish)
proxy: 如其名,这里的值是对应于 uplinks 的
对于1和2的值,我们通常有以下一些可选的配置:
$all 表示所有人都可以执行对应的操作
$authenticated 表示只有通过验证的人可以执行对应操作
$anonymous 表示只有匿名者可以进行对应操作(通常无用)
或者也可以指定对应于之前我们配置的用户表 htpasswd 中的一个或多个用户,这样就明确地指定哪些用户可以执行匹配的操作配置完成后,再运行:
配合 sinopia 使用
pm2:进程守护管理工具
$ npm install -g pm2 $ pm2 start `which sinopia`
更多操作参考 https://wohugb.gitbooks.io/pm2/content/
nrm:npm镜像地址管理工具
安全性
为了保证私有npm仓库,可以在前端加一层 Nginx,然后配置 SSH 来作为双层验证
The text was updated successfully, but these errors were encountered: