1. 起因
公司用nexus3搭建docker的私倉,由於是http的所以到處都需要配置惡心的insecure-registries!?!
這都不是事兒,但是如果遇到要改這個配置,問題就嚴重了...
2. 解決辦法
把私倉配置成https的就不需要配置了,所以趕緊找老板要了個證書,用nginx反代一波,
由於nexus pull 鏡像是從聚合倉庫,push鏡像走私倉,所以pull跟push有兩個端口,
需要根據http method反向代理一下,以下為nginx配置
server {
#SSL 訪問端口號為 443
listen 443 ssl;
#填寫綁定證書的域名
server_name xxx.xxx.xxx;
#證書文件名稱
ssl_certificate /etc/nginx/certificates/xxx.xxx.xxx_bundle.crt;
#私鑰文件名稱
ssl_certificate_key /etc/nginx/certificates/xxx.xxx.xxx.key;
ssl_session_timeout 5m;
#請按照以下協議配置
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
#請按照以下套件配置,配置加密套件,寫法遵循 openssl 標准。
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
ssl_prefer_server_ciphers on;
location / {
# pull 鏡像
if ($request_method ~* GET) {
proxy_pass http://xxx.xxx.xxx:xx;
}
# push 鏡像
if ($request_method ~* POST) {
proxy_pass http://xxx.xxx.xxx:xx;
}
if ($request_method ~* HEAD) {
proxy_pass http://xxx.xxx.xxx:xx;
}
if ($request_method ~* PUT) {
proxy_pass http://xxx.xxx.xxx:xx;
}
if ($request_method ~* PATCH) {
proxy_pass http://xxx.xxx.xxx:xx;
}
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; # 轉發時使用https協議
proxy_max_temp_file_size 0;
# This is the maximum upload size
client_max_body_size 1024m; #要設置大一點不然push鏡像push不上去
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_temp_file_write_size 64k;
# Required for new HTTP-based CLI
proxy_http_version 1.1;
proxy_buffering off; # Required for HTTP-based CLI to work over SSL
}
}