Last active
March 21, 2020 19:06
-
-
Save f9n/ad58454510e4d3939ef0fc0e7fe87a67 to your computer and use it in GitHub Desktop.
Nginx Reverse Proxy for Nexus Docker Registries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Credits | |
# https://visibilityspots.org/nexus-oss-repository-manager.html | |
user nginx; | |
worker_processes auto; | |
events { | |
worker_connections 1024; | |
} | |
http { | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
proxy_buffering off; | |
proxy_send_timeout 120; | |
proxy_read_timeout 300; | |
proxy_intercept_errors off; | |
keepalive_timeout 5 5; | |
types_hash_max_size 2048; | |
client_max_body_size 0; | |
upstream nexus { | |
server 0.0.0.0:8081; | |
} | |
upstream docker-private { | |
server 0.0.0.0:8083; | |
} | |
# Docker Hosted and Docker Proxy | |
upstream docker-group { | |
server 0.0.0.0:8082; | |
} | |
map $request_method $docker { | |
default "docker-private"; | |
"~GET" "docker-group"; | |
} | |
server { | |
listen 80; | |
server_name nexus.example.com; | |
return 301 https://$server_name$request_uri; | |
} | |
server { | |
listen 443 ssl http2; | |
server_name nexus.example.com; | |
ssl_certificate /etc/nginx/ssl/star_example_com.pem; | |
ssl_certificate_key /etc/nginx/ssl/star_example_com.key; | |
location / { | |
# 'docker' and 'Docker' for docker-cli | |
# 'Go-http-client', 'go-containerregistry', 'kaniko' for kaniko project | |
if ($http_user_agent ~ (docker|Docker|Go-http-client|go-containerregistry|kaniko)) { | |
proxy_pass http://$docker; | |
} | |
proxy_pass http://nexus; | |
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment