skip to content
Burak Berk Keskin
Table of Contents

Overview

Sonatype Nexus serves as a unified repository manager for Maven dependencies, npm packages, Docker images, and raw artifacts. While I prefer Harbor for dedicated container image registries, Nexus remains useful when multiple package ecosystems need to be cached in one place.

Deploying Nexus behind an Nginx reverse proxy in Docker Compose isolates the Java runtime from the host network while offloading TLS termination and virtual-host port routing to Nginx. Here is the containerized deployment layout I use for the Nexus Web UI and multiple Docker registry listeners.

Directory Structure

Create a project directory with subdirectories for Nginx configuration and TLS certificates:

Terminal window
mkdir nexus && cd nexus && \
mkdir -p config/ssl

Docker Compose Setup

Define the nexus and proxy services in docker-compose.yaml. Notice that nexus exposes no ports directly to the host; all ingress flows through Nginx:

docker-compose.yaml
services:
nexus:
image: "sonatype/nexus3:3.72.0"
volumes:
- "nexus-data:/nexus-data"
restart: always
proxy:
image: "nginx:alpine"
ports:
- "80:80"
- "443:443"
volumes:
- ./config/nginx.conf:/etc/nginx/nginx.conf
- ./config/ssl/:/etc/nginx/ssl
restart: always
volumes:
nexus-data:

Nginx Reverse Proxy Configuration

Because Nexus exposes each Docker registry connector on its own internal HTTP port, I map separate HTTPS server blocks in config/nginx.conf to route clean domain names without port suffixes:

  • registry.burakberk.dev → Nexus Web UI and Maven/npm endpoints (8081)
  • cr.burakberk.dev → Grouped Docker Hub and GitHub Container Registry proxy (8082)
  • redhat-registry.burakberk.dev → Standalone Red Hat container registry proxy (8083)
config/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
proxy_send_timeout 120;
proxy_read_timeout 300;
proxy_buffering off;
proxy_request_buffering off;
keepalive_timeout 5 5;
tcp_nodelay on;
server {
listen 80;
server_name registry.burakberk.dev;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl;
server_name registry.burakberk.dev;
ssl_certificate /etc/nginx/ssl/server.crt;
ssl_certificate_key /etc/nginx/ssl/server.key;
client_max_body_size 2G;
location / {
proxy_pass http://nexus:8081;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto "https";
}
}
server {
listen 443 ssl;
server_name cr.burakberk.dev;
ssl_certificate /etc/nginx/ssl/cr.crt;
ssl_certificate_key /etc/nginx/ssl/cr.key;
client_max_body_size 2G;
location / {
proxy_pass http://nexus:8082/;
proxy_set_header Host $host;
proxy_set_header X-REAL-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto "https";
}
}
server {
listen 443 ssl;
server_name redhat-registry.burakberk.dev;
ssl_certificate /etc/nginx/ssl/redhat-registry.crt;
ssl_certificate_key /etc/nginx/ssl/redhat-registry.key;
client_max_body_size 2G;
location / {
proxy_pass http://nexus:8083/;
proxy_set_header Host $host;
proxy_set_header X-REAL-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto "https";
}
}
}

TLS Certificates

For internal environments without Let’s Encrypt public DNS validation, I generate full-chain private CA certificates using crtforge and place each domain’s full-chain .crt and private .key inside config/ssl/:

  • registry.burakberk.dev: config/ssl/server.crt, config/ssl/server.key
  • cr.burakberk.dev: config/ssl/cr.crt, config/ssl/cr.key
  • redhat-registry.burakberk.dev: config/ssl/redhat-registry.crt, config/ssl/redhat-registry.key

The final directory layout looks like:

nexus
├── config
│ ├── nginx.conf
│ └── ssl
│ ├── server.crt
│ └── server.key
└── docker-compose.yaml

Starting and Initializing Nexus

Start both containers in detached mode:

Terminal window
docker compose up -d

Extract the generated initial admin password from the running Nexus container:

Terminal window
docker compose exec nexus cat /nexus-data/admin.password

Open https://registry.burakberk.dev in a browser and sign in with the retrieved credentials:

username: admin
password: <password from /nexus-data/admin.password>

After completing the initial setup wizard to rotate the admin password and toggle anonymous read access as needed, the instance is ready for repository provisioning—covered in my follow-up notes on configuring Nexus Maven, npm, and Docker repositories.