Since the server was in a LAN environment, our.NET expert had built ProGet earlier, and the need was to build a simple Nuget repo. Recently, I’ve been working on a project with Flask for a front and back end separation framework. So I decided to build a stronger software library management system with Nexus 3 OSS. To this end, I translated a previous article “Installing Sonatype Nexus Repository OSS on CentOS 7”, which felt very useful. The only difference is that I used Apache instead of Nginx. First, the flow can not reach the load pressure; Second, CentOS comes with Apache2.

Apache configuration

View modules:

$ httpd -M
Copy the code

The following information is displayed:

. . .
proxy_module (shared)
. . . 
lbmethod_byrequests_module (shared)
. . . 
proxy_balancer_module (shared)
. . . 
proxy_http_module (shared)
. . . 
Copy the code

If the module is not enabled, you can open the/etc/HTTPD/conf. Modules. D / 00 – proxy. To start the conf

$ vi /etc/httpd/conf.modules.d/00-proxy.conf
Copy the code

And uncomment lines with the necessary modules by removing the symbol from the beginning of the line with #, so the file looks like this:

. . . LoadModule proxy_module modules/mod_proxy.so . . . LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so . . . LoadModule proxy_balancer_module modules/mod_proxy_balancer.so . . . LoadModule  proxy_http_module modules/mod_proxy_http.so . . .Copy the code

For the changes to take effect, save the file and restart Apache.

$ sudo systemctl restart httpd
Copy the code

Configure proxy: the following content pasted to the/etc/HTTPD/conf. D/default. The conf file:

<VirtualHost *:80> ProxyPreserveHost On ProxyPass/http://127.0.0.1:8080/ ProxyPassReverse/http://127.0.0.1:8080/ </VirtualHost>Copy the code

PyPI

  1. Visit http://< Apache IP>/, log in to apache, and construct the Hosted PyPI

  2. To download the python project dependencies, see reference 2

    • Direct download

      $PIP download Requests Certifi-2020.4.5.1 -py2.py3-none-any. WHL chardet-3.0.4-py2.py3-none-any. WHL Idna - 2.9 - py2. Py3 - none - any. WHL requests - 2.23.0 - py2. Py3 - none - any. WHL urllib3-1.25.9 - py2. Py3 - none - any. WHLCopy the code
    • Get only dependencies

      # Install pipdeptree: $PIP Install pipdeptree $pipdeptree -p requests requests==2.23.0 - Certifi [required: >=2017.4.17, installed: 2020.4.5.1] - chardet [Required: >=3.0.2,<4, installed: 3.0.4] - IDna [Required: > = 2.5, the < 3, the installed: 2.9] - urllib3 [required: > = 1.21.1, < 1.26,! = 1.25.1,! = 1.25.0, installed: 1.25.9]Copy the code

      Save the information to requirements.txt

      Certifi > = 2017.4.17 chardet 3.0.2 = >, < 4 idna > = 2.5, < 3 urllib3 > = 1.21.1, < 1.26,! = 1.25.1,! = 1.25.0Copy the code

      Download the dependency packages according to requirements.txt

        (current directory) $ pip download -r requirements.txt
      Copy the code
  3. Upload the WHL file to the corresponding PyPI library. You can upload them using Twine or individually on the Nexus page.

  4. $PIP install package -i http://< IP or domain name >/repository/pypi- Hosted /simple –trusted-host < IP or domain name >

NPM

  1. Visit http://< Apache IP>/, log in to apache, and construct the HOSTED NPM

  2. Refs. 4

    • Download the NPM package

      1. In the project directory, create a folder to store the offline NPM packages

         yarn config set yarn-offline-mirror ./npm-packages-offline-cache
        Copy the code
      2. Set offline cache mode and generate a.yarnrc file in the project directory

         yarn config set yarn-offline-mirror-pruning true
        Copy the code
      3. Move the. Yarnrc file to the project directory

         mv ~/.yarnrc ./
        Copy the code
      4. Delete the yarn.lock file

         rm -rf node_modules/ yarn.lock
        Copy the code
      5. Install the NPM package

         yarn install
        Copy the code
    • Batch upload

      1. Configure the NPM warehouse address

        NPM config -g set registry Remote repository addressCopy the code
      2. Logging In to the Hosted Warehouse

        NPM adduser-registry = Address of the NPM repository of type HostedCopy the code
      3. For Nexus setup Security – >Realms, add “NPM Bearer Token Realm”. Notice this is important.

      4. Upload bat scripts in batches

        @echo off :: init params set deployFile=*.tar.gz set deployFile2=*.tgz set url=http://xxx.xxx.xx.xx/repository/npm-hosted/ echo Searching tar.gz and tgz file... Rem enables "Delay environment variable expansion" SETLOCAL ENABLEDELAYEDEXPANSION for %% in (%deployFile% %deployFile2%) do (set name=%%f echo! name! to deploy to %url% rem deploy to server call npm publish -registry=%url% ! name! ) pauseCopy the code
  3. Note: if you use Nginx, you can skip this paragraph. Apache is a bit of a trap and not smart about urls with slashes. So you need to configure it. Thank you very much for the second answer of material 5:

    /usr/sbin/httpd # /usr/sbin/httpd Apache / 2.4.6 (CentOS)... # vim/etc/HTTPD/conf. D/default - site. The conf # agent configuration file beforeCopy the code

    A change on

    AllowEncodedSlashes NoDecode ProxyPass/http://127.0.0.1:8081/ nocanon..Copy the code

conclusion

Sonatype Nexus Repository OSS is really nice, the open source versions are so powerful. The repO for Maven, Nuget, and Docker, which I haven’t used for a while, has comprehensive support for dependencies. It is recommended that developers with private NAS can also install a try. Finally, I would like to thank the authors for their interpretation and sharing of Nexus, PyPI and NPM issues. I hope this article can also be used by readers.

reference

  1. How To Use Apache as a Reverse Proxy with mod_proxy on CentOS 7
  2. How To Download Python Dependencies
  3. Use Nexus to build PyPi private server
  4. FE (13) Front-end Nexus3 Yarn Deploy the NPM repository offline
  5. Nexus 3 as npm repository can’t find some dependencies: npm ERR! 404 Not Found