So we have an nginx proxy cache that is used to maintain uptime even if npm goes down.
On occasion this server (noticeably once every few months) starts returning 400 bad request
for every response for some specific package. I figured it was a corrupted cache or something. So we wipe the cache and then we can npm install
again. We tried simply restarting the server but that turns out to not be enough. It's worth mentioning the actual source (npm itself) returns 200OK for the same object (namely the tar.gz files).
Here is the config: https://github.com/parris/private-npm-registry/blob/master/nginx/server.conf (feel free to explore the surrounding files).
The config looks like this:
server {
listen 8888;
server_name localhost;
location / {
proxy_pass https://registry.npmjs.org/;
proxy_cache npm;
proxy_cache_valid 200 302 3d;
proxy_cache_valid 404 1m;
# npm adds "_resolved": 'registry.npmjs.org/xyz.tgz" to package.json files
# this rewrites things correctly
sub_filter 'registry.npmjs.org' 'localhost:8888';
sub_filter_once off;
sub_filter_types application/json;
}
}