最终看起来像这样 nginx (host,ssl) -> harbor-nginx (non-ssl) -> harbor。
说明
首先服务上安装有 nginx,且配置了 SSL,现在可能在本机或者内网的其他机器上安装有 Harbor,需要反向代理到本机映射出去。
harbor.yml
首先需要注释掉 https 相关的配置,并添加 external_url 的配置项。
# .........忽略其他..............
# Uncomment external_url if you want to enable external proxy
# And when it enabled the hostname will no longer used
external_url: https://docker.example.com
# .........忽略其他..............
配置完成后重启harbor
sudo ./install.sh
nginx 配置文件 harbor.conf
在 nginx 的 vhost 中新增相关配置,必须要配置 X-Forwarded-Proto $scheme,client_max_body_size 按需配置。
server {
listen 80;
server_name hub.example.cn;
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 443 ssl http2;
server_name docker.example.com;
ssl_certificate /usr/local/openresty/nginx/conf/ssl/hub.example.cn.crt;
ssl_certificate_key /usr/local/openresty/nginx/conf/ssl/hub.example.cn.key;
client_max_body_size 500m;
location / {
proxy_pass http://192.168.1.2:5080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-PORT $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
配置完成后重新加载nginx配置
sudo nginx -s reload
或者docker版nginx
sudo docker exec -it nginx(容器id/名称) nginx -s reload
harbor 内没有配置 external_url。
harbor 内需要取消 https 的配置。
反向代理 nginx 中没有配置 X-Forwarded-Proto $scheme。
https://blog.xqlee.com/article/2502221133212232.html