I have been working for a week on a npm proxy in nexus (version: OSS 3.47.1-01) that connects to a remote npm storage behind a proxy server, and I still failed to make it work. Here is the network topology:
| <----------------inner network---------------------> | <----------outer network----------> |
MyComputer <----> Nexus (Npm Proxy) <----> (10205) Proxy Server <----> (80) Remote Npm Storage
The port configured in the Proxy Server for redirecting npm requests is 10205, and the Proxy Server should redirect all the npm requests to port 80 of the Remote Npm Storage. When configuring the Npm Proxy in Nexus (through a website frontend), the Remote storage
field is set to http://ProxyServer:10205/aa/bb/cc
. But when I try to use My Computer to pull packages from Remote Npm Storage, e.g. by npm install
, I find that Nexus sends fetch requests to port 80 of the Proxy Server instead of port 10205. For examples, it is expected that the Npm Proxy in Nexus sends requests to http://ProxyServer:10205/aa/bb/cc/xyz.tgz
to pull xyz.tgz, but it actually send the requests to http://ProxyServer:80/aa/bb/cc/xyz.tgz
, which leads to connection failure.
I have no idea what cased the port changed.
I have tried two different workarounds that can make things work:
-
Change the configured port of Proxy Server to 80: When configuring the Npm Proxy in Nexus, the
Remote storage
is set tohttp://ProxyServer:80/aa/bb/cc
. In that case, I can download npm packages in My Computer through Nexus. -
Bypass Nexus: I also tried connecting directly to Remote Npm Storage via Proxy Server, while bypassing nexus. Here are the settings in my
.npmrc
file:
registry = http://RemoteNpmStorage:80/aa/bb/cc
proxy = http://ProxyServer:10205
https-proxy = http://ProxyServer:10205
In that case, I can also download npm packages in My Computer through Nexus. One interesting finding is that, if I set registry
in the .npmrc
file to the Proxy Server, I get the same problem (i.e., port changed) as the one when using Nexus:
registry = http://ProxyServer:10205/aa/bb/cc
Besides, a third workaround that might work is that: 1) I set the Remote storage
of the Npm Proxy to http://RemoteNpmStorage:80/aa/bb/cc
; and 2) I add some repository-specific proxy settings such that the Npm Proxy could communicate with the Remote Npm Storage through http://ProxyServer:10205
. What I can find in Nexus frontend is that, under Administration > System > HTTP > ProxySetting
, we can change the proxy settings for the entire Nexus. However, the Npm Proxy is not the only repository in Nexus, I cannot change the global proxy settings as that affects all the repositories in Nexus.
Any help or hint would be highly appreciated. Thanks!