Nginx 代理 Harbor: 配置 external_url 和端口转发
Nginx 代理 Harbor: 配置 external_url 和端口转发
本教程将详细介绍如何使用 Nginx 代理 Harbor,并将请求从 Nginx 的 8080 端口转发到 Harbor 的 30001 端口。
1. 配置 Harbor.yml 文件中的 external_url 参数
在 Harbor.yml 文件中,找到 external_url 参数,将其设置为 Nginx 代理的 URL,例如:
external_url: 'http://example.com/harbor'
其中,example.com/harbor 是 Nginx 代理的 URL,harbor 是 Harbor 的根路径。
2. 配置 Nginx 代理
在 Nginx 的配置文件中添加以下配置:
server {
listen 8080;
server_name example.com;
location /harbor/ {
proxy_pass http://localhost:30001/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
其中,example.com 是你的域名,/harbor/ 是 Harbor 的根路径,http://localhost:30001/ 是 Harbor 的实际地址。
3. 重启 Nginx 和 Harbor
完成上述配置后,重启 Nginx 和 Harbor 服务使配置生效。
sudo systemctl restart nginx
sudo systemctl restart docker-compose@harbor
现在,你可以通过访问 http://example.com/harbor 来访问 Harbor 了。Nginx 会将请求转发到 Harbor 的实际地址,从而实现代理。
原文地址: https://www.cveoy.top/t/topic/j8nH 著作权归作者所有。请勿转载和采集!