I ran into this exact problem. We install the nginx proxy in front of the private npm registry. We backed up the global npm 404 registry.
So, when installing npm, we just need to specify the nginx proxy, and this will take care of serving the package from the private registry if it is found, or the global registry if not.
This is the nginx configuration you can use:
server {
listen 80 default_server;
location ~ ^/registry/*/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://private_npm_upstream;
proxy_intercept_errors on;
error_page 404 = @fallback-2;
proxy_redirect off;
}
location @fallback-2 {
access_log /var/log/nginx/global_npm.access.log;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host registry.npmjs.org;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://registry.npmjs.org;
proxy_redirect off;
proxy_intercept_errors on;
}
}
upstream global_npm_upstream {
server registry.npmjs.org;
}
upstream private_npm_upstream {
server 127.0.0.1:5984;
}
source
share