Skip to content

Two engines behind nexus-proxy

What it is

nexus-proxy is the front for two or more engines that share one state directory (High availability). It ships in the Linux kit, beside nexus, and as its own container image. It terminates TLS and spreads requests round robin over the engines that are healthy. A request that reached an engine is never sent to another, so a flow never runs twice because the proxy retried it. It learns which engines are healthy by asking each one GET /ready. nexus-proxy --version prints the proxy’s own version, which is not the engine’s.

This page puts the proxy on a host of its own. Two VMs that each run an engine and a proxy are installed step by step in High availability on two VMs.

It does not do per-route or per-path rate limits, address allowlists, request filtering or caching, and it does not reload its configuration: a change takes a restart. Per-caller rate limits and identity-provider tokens need nothing from the front: the engine applies and validates them, and the proxy passes Authorization through unchanged. A site that needs per-route limits, an address allowlist or request filtering at the front keeps a proxy that does them, as Gateway boundary describes.

A stop drains: the proxy refuses new connections, lets the requests in flight finish within drain_ms, and exits with code 0; exit code 1 means some were still running at drain_ms and were cut.

On Linux, from the kit

Run as root, from the directory where the kit was extracted, on the host that will run the proxy:

Terminal window
useradd --system --user-group --home-dir /nonexistent --shell /usr/sbin/nologin nexus-proxy
install -o root -g root -m 0755 nexus-<version>-linux-<arch>/nexus-proxy /usr/local/bin/nexus-proxy
install -d -o root -g nexus-proxy -m 0750 /etc/nexus-proxy
install -o root -g nexus-proxy -m 0640 /dev/null /etc/nexus-proxy/proxy.json
install -o root -g nexus-proxy -m 0640 /dev/null /etc/nexus-proxy/proxy.crt
install -o root -g nexus-proxy -m 0640 /dev/null /etc/nexus-proxy/proxy.key

The proxy runs under its own account, so it cannot read the engine’s /etc/nexus/nexus.env nor the engine’s state directory, whose group is nexus. The three files exist with mode 0640 before anything is written into them, so no umask decides who can read the key. Write the server certificate chain, in PEM, into proxy.crt, its private key into proxy.key, and the configuration below into proxy.json.

The configuration

/etc/nexus-proxy/proxy.json:

{
"listen": "0.0.0.0:443",
"tls": {
"certificate": "/etc/nexus-proxy/proxy.crt",
"private_key": "/etc/nexus-proxy/proxy.key"
},
"engines": ["10.0.0.11:9090", "10.0.0.12:9090"]
}

Every other key keeps its default; every key is listed below. The engines are IP addresses with a port, because the proxy resolves no host name: a name that resolves differently tomorrow would move traffic without a restart.

Each engine listens for the proxy and trusts it

The install page’s unit binds the engine to 127.0.0.1, which the proxy on another host cannot reach. On each engine host, systemctl edit nexus opens a drop-in for that unit; this one changes only its command line:

[Service]
ExecStart=
ExecStart=/opt/nexus/nexus serve --host 0.0.0.0 --port 9090 --db /var/lib/nexus/registry.db --trusted-proxy 10.0.0.10

10.0.0.10 is the proxy’s address. --trusted-proxy lets the engine believe the proxy’s X-Forwarded-Proto and Client-Cert headers, and nobody else’s (see Gateway boundary). The empty ExecStart= clears the unit’s own line before the new one; every other line of the install page’s unit stays in force. Allow port 9090 on the engine hosts only from the proxy’s address, with the host’s firewall.

The unit

/etc/systemd/system/nexus-proxy.service:

[Unit]
Description=nexus-proxy
After=network.target
[Service]
User=nexus-proxy
Group=nexus-proxy
ExecStart=/usr/local/bin/nexus-proxy --config /etc/nexus-proxy/proxy.json
Restart=on-failure
RestartSec=5
TimeoutStopSec=45
NoNewPrivileges=yes
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE
UMask=0027
ProtectSystem=strict
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
ProtectClock=yes
ProtectHostname=yes
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
RestrictNamespaces=yes
RestrictRealtime=yes
RestrictSUIDSGID=yes
LockPersonality=yes
MemoryDenyWriteExecute=yes
SystemCallArchitectures=native
SystemCallFilter=@system-service
SystemCallErrorNumber=EPERM
[Install]
WantedBy=multi-user.target

The confinement is the engine’s, from the install page’s unit, with two differences. The proxy keeps one capability, CAP_NET_BIND_SERVICE, the one a port below 1024 such as 443 needs. It has no ReadWritePaths=: with its default logs on stdout and stderr it writes no file, and the journal collects both. A log written to a file needs its directory added with ReadWritePaths=; see nexus-proxy logs.

TimeoutStopSec=45 is above the default drain_ms of 30 seconds, so systemd lets the drain end before it kills the process. Raise it with drain_ms.

Then start it and check it:

Terminal window
systemctl daemon-reload
systemctl enable --now nexus-proxy
nexus-proxy --version
systemctl status nexus-proxy
journalctl -u nexus-proxy

The journal holds nexus-proxy listening on 0.0.0.0:443 once the port is bound, then one engine_state line each time an engine becomes healthy or unhealthy.

Every configuration key

Key Default What it does
listen required The address and port the proxy accepts connections on, such as 0.0.0.0:443.
engines required The engines’ HTTP addresses, 1 to 16 IP addresses with a port, none twice.
max_body_bytes 1048576 The largest request body accepted; a larger one is answered 413 and never reaches an engine.
body_limits none A list of { "prefix": "/…", "max_body_bytes": n }: the limit for paths that start with prefix, in place of max_body_bytes.
timeouts.connect_ms 2000 How long to wait for a connection to an engine.
timeouts.response_ms 60000 How long to wait for an engine’s response head once the request was sent; then 504.
timeouts.upstream_idle_ms 4000 How long an idle connection to an engine is kept; must be below the engine’s keep-alive of 5000.
timeouts.client_header_ms 30000 On both listeners, how long a client has to complete the TLS handshake, send the gRPC listener’s HTTP/2 preface, send the request head on HTTP/1.x, and how long a connection may stay open with no request in flight: on HTTP/1.1 between two requests, on HTTP/2 with no stream open. Then the connection is closed, on HTTP/2 after a GOAWAY. Frames that open no stream do not keep a connection open.
timeouts.client_body_ms 60000 How long a client has to send the whole body after the head; then 408, or DEADLINE_EXCEEDED on the gRPC listener.
timeouts.client_send_ms 60000 On both listeners, how long a response may wait for its client to accept any byte of it; time spent waiting for the engine does not count. Then the response is cut (the connection closed on HTTP/1.x, the stream reset on HTTP/2), the engine connection released, and the access line written with outcome client_timeout and a bytes_out that is an upper bound of what reached the client.
health.interval_ms 2000 How often each engine is asked GET /ready.
health.timeout_ms 1000 How long one GET /ready may take before it counts as a failure.
health.unhealthy_after 2 Consecutive failures after which an engine stops receiving requests.
health.healthy_after 2 Consecutive successes after which it receives them again.
tls.certificate none The server certificate chain, PEM, absolute path. Without tls, the proxy listens in plain HTTP.
tls.private_key none The certificate’s private key, PEM, absolute path.
tls.client_auth.mode none optional or required: ask clients for a certificate, and refuse a connection without one when required. Without client_auth, none is asked.
tls.client_auth.ca none The CA certificates, PEM, that client certificates must chain to.
tls.client_auth.crls none The certificate revocation lists, a non-empty list of absolute paths, PEM or DER.
tls.client_auth.crl_reload_ms 300000 How often the CRL files are read again.
grpc.listen none A second listener for gRPC callers. Without grpc, none is opened.
grpc.engines none The engines’ gRPC doors (nexus serve --grpc-port), one per entry of engines, in the same order.
drain_ms 30000 How long a stop waits for the requests in flight before it cuts them and exits with code 1.
status_listen none A loopback address and port, such as 127.0.0.1:9100, on which the proxy itself answers GET /status with 200, for the check of the virtual address. It writes no log line and closes when a stop begins. Without it, nothing is opened.
access_log, error_log stdout, stderr Where the two logs go, and how a log file rotates: see nexus-proxy logs.

Every duration is in milliseconds and every number is a positive integer. An unknown key, or a value out of range, stops the start with exit code 2 and one line on stderr that names the key, such as nexus-proxy: invalid config: /etc/nexus-proxy/proxy.json: timeouts.upstream_idle_ms: must be below 5000, the engine's keep-alive.

In a container, from the image archive

Verify the proxy image archive and load it as Verifying a kit describes; it loads as ghcr.io/iello/nexusfabric-proxy:<version>. Then:

Terminal window
docker run -d --name nexus-proxy --read-only -v /etc/nexus-proxy:/etc/nexus-proxy:ro -p 443:8443 --stop-timeout 45 ghcr.io/iello/nexusfabric-proxy:<version>

The image runs as a non-root user, which cannot bind a port below 1024, so in a container the configuration says "listen": "0.0.0.0:8443" and Docker maps 443 to it. The files under /etc/nexus-proxy must be readable by that user, whose group is 999: give the directory and its three files that group, with the modes above. --stop-timeout, in seconds, is above drain_ms for the same reason as TimeoutStopSec=.

Installing a proxy-only release

A proxy-only release replaces the proxy and leaves the engine alone: no engine is stopped, and the engine’s kit and image are not touched. Verify its archives first, as that section says. The kit extracts to nexus-proxy-<version>-linux-<arch>/, which holds nexus-proxy and nothing else.

On Linux, as root, from the directory where the kit was extracted, put the program at the path, with the owner and mode, it was installed with above, then restart each unit that runs it:

Terminal window
install -o root -g root -m 0755 nexus-proxy-<version>-linux-<arch>/nexus-proxy /usr/local/bin/nexus-proxy
systemctl restart nexus-proxy
nexus-proxy --version

nexus-proxy --version prints the version now installed. The restart drains as a stop does.

In a container, load the image archive as that section says; it loads as ghcr.io/iello/nexusfabric-proxy:proxy-<version>. Remove the running container and start it again from that image, with the configuration it already mounts:

Terminal window
docker stop nexus-proxy
docker rm nexus-proxy
docker run -d --name nexus-proxy --read-only -v /etc/nexus-proxy:/etc/nexus-proxy:ro -p 443:8443 --stop-timeout 45 ghcr.io/iello/nexusfabric-proxy:proxy-<version>