使用verdaccio搭建自己的私有仓库
服务器安装node,点击详情
安装verdaccio
npm install -g verdaccio --unsafe-perm
输入verdaccio可查看效果
verdaccio
vim /*/verdaccio/config.yaml
在后面添加
listen: 0.0.0.0:4873
# 在文件末尾增加以下配置
url_prefix: /verdaccio/
同时在nginx配置做反向代理,nginx -t可以看到配置文件位置
location ~ ^/verdaccio/(.*)$ {proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;proxy_set_header X-NginX-Proxy true;proxy_set_header Host $host:$server_port;proxy_set_header X-Forwarded-For $remote_addr;proxy_set_header X-Forwarded-Proto $scheme;proxy_headers_hash_max_size 1024;proxy_headers_hash_bucket_size 128;proxy_pass http://127.0.0.1:4873/$1;proxy_redirect off;}
重启nginx
nginx -s reload
此时访问http://*.com/verdaccio/可以看到verdaccio的首页
使用pm2可以开启verdaccio
pm2 start `which verdaccio`
在本地cmd测试,首先注册账号
npm adduser --registry http://.com/verdaccio/
可以通过nrm切换数据源,目前的nrm的open报错,需要指定版本
npm install nrm open@8.4.2 -g
通过nrm添加npm地址配置,切换配置
修改verdaccio/config.yaml的配置文件,禁止用户注册
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# Hash algorithm, possible options are: "bcrypt", "md5", "sha1", "crypt".# algorithm: bcrypt # by default is crypt, but is recommended use bcrypt for new installations# Rounds number for "bcrypt", will be ignored for other algorithms.# rounds: 10
禁止注册可以在verdaccio文件下使用sinopia-adduser注册
npm i -g sinopia-adduser
npm publish -registry -url