如果nexus3已经安装完成之后,通过nginx进行统一负载,以下是https
或http
的例子。
如果您还未搭建nexus3,则看上篇:
nexus3搭建docker镜像仓库及google镜像代理
http
upstream nexus_admin { server 127.0.0.1:8081 ; }
upstream nexus_registry { server 127.0.0.1:8082 ; }
server {
listen 80;
server_name localhost;
add_header X-Frame-Options SAMEORIGIN;
location / {
client_max_body_size 0;
chunked_transfer_encoding on;
add_header Docker-Distribution-Api-Version: registry/2.0 always;
proxy_http_version 1.1;
proxy_set_header Connection "";
if ($http_user_agent ~* "docker") { proxy_pass http://nexus_registry; }
if ($http_user_agent ~* "Chrome|Mozilla") { proxy_pass http://nexus_admin; }
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 $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_redirect off;
}
}
https
upstream nexus_admin { server 127.0.0.1:8081 ; }
upstream nexus_registry { server 127.0.0.1:5001 ; }
server {
listen 80;
listen 443 ssl ;
server_name docker.domain.com;
access_log /dev/null;
error_log /app/logs/nginx/docker.domain.com.error.log;
ssl_certificate server.pem;
ssl_certificate_key server.key;
ssl_session_timeout 20m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers EECDH+AES:EECDH+CHACHA20;
add_header X-Frame-Options SAMEORIGIN;
location / {
client_max_body_size 0;
chunked_transfer_encoding on;
add_header Docker-Distribution-Api-Version: registry/2.0 always;
proxy_http_version 1.1;
proxy_set_header Connection "";
if ($http_user_agent ~* "docker") { proxy_pass http://nexus_registry; }
if ($http_user_agent ~* "Chrome|Mozilla") { proxy_pass http://nexus_admin; }
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 $scheme;
proxy_set_header X-Forwarded-Port $server_port;
proxy_redirect off;
}
}
docker-compose.yml
version: "2"
services:
nexus:
image: sonatype/nexus3:3.6.0
volumes:
- "/app/srv/docker/nexus3:/nexus-data"
ports:
- "8081:8081"
- "5001:5001"
environment:
# - NEXUS_CONTEXT=nexus
- JAVA_OPTS=" -Xmx2048m"
mem_limit: 2g
mem_swappiness: 0
## chown -Rv 200 /app/srv/docker/nexus3
## admin/admin123