私有npm搭建

https://juejin.cn/post/6844903776533364749

  1. cd /root/.config/verdaccio/
  2. pm2 start verdaccio
  3. pm2 restart verdaccio

完整配置如下:

  1. #
  2. # This is the default config file. It allows all users to do anything,
  3. # so don't use it on production systems.
  4. #
  5. # Look here for more config file examples:
  6. # https://github.com/verdaccio/verdaccio/tree/master/conf
  7. #
  8. # path to a directory with all packages
  9. storage: ./storage
  10. # path to a directory with plugins to include
  11. plugins: ./plugins
  12. web:
  13. title: Verdaccio
  14. # comment out to disable gravatar support
  15. # gravatar: false
  16. # by default packages are ordercer ascendant (asc|desc)
  17. # sort_packages: asc
  18. # convert your UI to the dark side
  19. # darkMode: true
  20. # logo: http://somedomain/somelogo.png
  21. # favicon: http://somedomain/favicon.ico | /path/favicon.ico
  22. # rateLimit:
  23. # windowMs: 1000
  24. # max: 10000
  25. # translate your registry, api i18n not available yet
  26. # i18n:
  27. # list of the available translations https://github.com/verdaccio/ui/tree/master/i18n/translations
  28. # web: en-US
  29. auth:
  30. htpasswd:
  31. file: ./htpasswd
  32. # Maximum amount of users allowed to register, defaults to "+inf".
  33. # You can set this to -1 to disable registration.
  34. # max_users: 1000
  35. # a list of other known repositories we can talk to
  36. uplinks:
  37. npmjs:
  38. url: https://registry.npmjs.org/
  39. packages:
  40. '@*/*':
  41. # scoped packages
  42. access: $all
  43. publish: $authenticated
  44. unpublish: $authenticated
  45. proxy: npmjs
  46. '**':
  47. # allow all users (including non-authenticated users) to read and
  48. # publish all packages
  49. #
  50. # you can specify usernames/groupnames (depending on your auth plugin)
  51. # and three keywords: "$all", "$anonymous", "$authenticated"
  52. access: $all
  53. # allow all known users to publish/publish packages
  54. # (anyone can register by default, remember?)
  55. publish: $authenticated
  56. unpublish: $authenticated
  57. # if package is not available locally, proxy requests to 'npmjs' registry
  58. proxy: npmjs
  59. # You can specify HTTP/1.1 server keep alive timeout in seconds for incoming connections.
  60. # A value of 0 makes the http server behave similarly to Node.js versions prior to 8.0.0, which did not have a keep-alive timeout.
  61. # WORKAROUND: Through given configuration you can workaround following issue https://github.com/verdaccio/verdaccio/issues/301. Set to 0 in case 60 is not enough.
  62. server:
  63. keepAliveTimeout: 60
  64. middlewares:
  65. audit:
  66. enabled: true
  67. # log settings
  68. logs: { type: stdout, format: pretty, level: http }
  69. #experiments:
  70. # # support for npm token command
  71. # token: false
  72. # # disable writing body size to logs, read more on ticket 1912
  73. # bytesin_off: false
  74. # # enable tarball URL redirect for hosting tarball with a different server, the tarball_url_redirect can be a template string
  75. # tarball_url_redirect: 'https://mycdn.com/verdaccio/${packageName}/${filename}'
  76. # # the tarball_url_redirect can be a function, takes packageName and filename and returns the url, when working with a js configuration file
  77. # tarball_url_redirect(packageName, filename) {
  78. # const signedUrl = // generate a signed url
  79. # return signedUrl;
  80. # }
  81. # This affect the web and api (not developed yet)
  82. #i18n:
  83. #web: en-US
  84. # you can specify listen address (or simply a port)
  85. listen: 0.0.0.0:4873
  86. url_prefix: /npm/

npm配置

  1. cd /etc/nginx/conf.d
  2. vim default_ssl.conf
  1. # private npm verdaccio
  2. location /npm/ {
  3. proxy_pass http://127.0.0.1:4873/;
  4. proxy_set_header Host $host:$server_port;
  5. proxy_set_header X-Forwarded-For $remote_addr;
  6. proxy_set_header X-Forwarded-Proto $scheme;
  7. }