Apache2 as Reverse Proxy for NPM Registry Proxies in Sonatype Nexus 3

Share on:

I use a NPM registry proxy in Sonatype Nexus 3 behind an Apache2 as reverse proxy. With the "standard" Apache2 VirtualHost configuration

1<VirtualHost:80>
2  ProxyRequests Off
3  <Proxy *>
4    Order deny,allow
5    Allow from all
6  </Proxy>
7  ProxyPass / http://localhost:8081/
8  ProxyPassReverse / http://localhost:8081/
9</VirtualHost:80>

I got following failure when I tried to install the dependency @sinonjs/formatio.

 1$ yarn add @sinonjs/formatio --verbose
 2 yarn add v1.3.2
 3 warning package.json: No license field
 4 verbose 0.337 Checking for configuration file "/home/sparsick/dev/workspace/yarn-test-module/.npmrc".
 5 verbose 0.337 Checking for configuration file "/home/sparsick/.npmrc".
 6 verbose 0.337 Found configuration file "/home/sparsick/.npmrc".
 7 verbose 0.337 Checking for configuration file "/usr/etc/npmrc".
 8 verbose 0.338 Found configuration file "/usr/etc/npmrc".
 9 verbose 0.338 Checking for configuration file "/home/sparsick/dev/workspace/yarn-test-module/.npmrc".
10 verbose 0.338 Checking for configuration file "/home/sparsick/dev/workspace/.npmrc".
11 verbose 0.338 Checking for configuration file "/home/sparsick/dev/.npmrc".
12 verbose 0.338 Checking for configuration file "/home/sparsick/.npmrc".
13 verbose 0.338 Found configuration file "/home/sparsick/.npmrc".
14 verbose 0.338 Checking for configuration file "/home/.npmrc".
15 verbose 0.341 Checking for configuration file "/home/sparsick/dev/workspace/yarn-test-module/.yarnrc".
16 verbose 0.342 Found configuration file "/home/sparsick/dev/workspace/yarn-test-module/.yarnrc".
17 verbose 0.343 Checking for configuration file "/home/sparsick/.yarnrc".
18 verbose 0.344 Found configuration file "/home/sparsick/.yarnrc".
19 verbose 0.344 Checking for configuration file "/usr/etc/yarnrc".
20 verbose 0.344 Checking for configuration file "/home/sparsick/dev/workspace/yarn-test-module/.yarnrc".
21 verbose 0.345 Found configuration file "/home/sparsick/dev/workspace/yarn-test-module/.yarnrc".
22 verbose 0.345 Checking for configuration file "/home/sparsick/dev/workspace/.yarnrc".
23 verbose 0.345 Checking for configuration file "/home/sparsick/dev/.yarnrc".
24 verbose 0.345 Checking for configuration file "/home/sparsick/.yarnrc".
25 verbose 0.345 Found configuration file "/home/sparsick/.yarnrc".
26 verbose 0.345 Checking for configuration file "/home/.yarnrc".
27 verbose 0.347 current time: 2018-02-27T08:04:43.357Z warning yarn-test-module: No license field \[1/4\] Resolving packages...
28 verbose 0.45 Performing "GET" request to "http://mycompany/repository/npm-public/@sinonjs%2fformatio".
29 verbose 0.55 Request "http://mycompany/repository/npm-public/@sinonjs%2fformatio" finished with status code 404.
30 verbose 0.551 Error: Couldn't find package "@sinonjs/formatio" on the "npm" registry. at /usr/lib/node\_modules/yarn/lib/cli.js:49061:15 at Generator.next (<anonymous>) at step (/usr/lib/node\_modules/yarn/lib/cli.js:92:30) at /usr/lib/node\_modules/yarn/lib/cli.js:103:13 at <anonymous> at process.\_tickCallback (internal/process/next\_tick.js:188:7) error Couldn't find package "@sinonjs/formatio" on the "npm" registry. info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.

The problem is that Apache2 canonicalizes URLs as default. So I have to configure Apache2 to not canonicalize URLs and additionally, I have to allow encoded slashes:

 1<VirtualHost:80>
 2
 3  ProxyRequests Off
 4  <Proxy *>
 5    Order deny,allow
 6    Allow from all
 7  </Proxy>
 8  ProxyPass / http://localhost:8081/ nocanon
 9  ProxyPassReverse / http://localhost:8081/
10
11  AllowEncodedSlashes NoDecode
12
13</VirtualHost:80>

With the above Apache2 Virtualhost configuration I could install my dependency via the NPM registry proxy.

 1$ yarn add @sinonjs/formatio
 2
 3yarn add v1.3.2
 4warning package.json: No license field
 5info No lockfile found.
 6warning yarn-test-module: No license field
 7[1/4] Resolving packages...
 8[2/4] Fetching packages...
 9[3/4] Linking dependencies...
10[4/4] Building fresh packages...
11success Saved lockfile.
12success Saved 2 new dependencies.
13├─ @sinonjs/formatio@2.0.0
14└─ samsam@1.3.0
15warning yarn-test-module: No license field
16Done in 0.60s.

Big thanks to Sonatype support team, that gave me this advice.

comments powered by Disqus