Configuring Custom Domain for Harbor on Linode: A Technical Guide

Technical Setup of Harbor Custom Domain on Linode

A technical walkthrough on setting up a custom domain for Harbor on Linode, including Nginx configurations and SSL certification via Certbot.

10th Apr 2024

harborcustom-domainlinodenginxsslcertbot

Deploying Harbor through Linode's marketplace is straightforward until you encounter the domain configuration. Linode's default domain service doesn't cover custom domain setup for Harbor, a gap this guide aims to fill.

Initial SSH Access

Start by securing SSH access to your Linode instance. This can be achieved via a local terminal or through Linode's Lish console. Navigate to the Nginx configuration directory at /etc/nginx/sites-available.

Nginx Configuration File

Within the sites-available directory, create a new configuration file for your domain, e.g., harbor.example.com, with the following content:

/etc/nginx/sites-available/harbor.example.comnginx
server {
   server_name harbor.example.com;
   error_log /var/log/nginx/harbor.example.com.error;
   access_log /var/log/nginx/harbor.example.com.access;

   location / {
      proxy_pass http://localhost:8000;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-Proto $scheme; # Ensures proper forwarding to Harbor's Docker container
   }
}

This configuration sets the groundwork for HTTPS activation with Certbot, particularly noting the inclusion of proxy_set_header X-Forwarded-Proto $scheme;, which is absent in the default setup and crucial for proper request forwarding.

SSL Certification with Certbot

Execute certbot for SSL certification, selecting harbor.example.com during the process. Follow the on-screen instructions to complete the setup.

Updating Nginx's nginx.conf

Modify /etc/nginx/nginx.conf by inserting client_max_body_size 10G; within the primary http block. This adjustment caters to larger Docker image layers, customizable based on your requirements.

/etc/nginx/nginx.confnginx
http {
   client_max_body_size 10G;
   ...
}

Harbor Configuration Adjustments

Alter /root/harbor/harbor.yml to update the hostname to harbor.example.com and set external_url to https://harbor.example.com. This change ensures correct URL formatting, eliminating the default port inclusion.

Finalizing with Docker Compose

With configurations in place, decompose the current Harbor setup with sudo docker-compose down -v. Prepare the environment with sudo ./prepare or sudo ./prepare --with-trivy for Trivy integration. Finally, deploy the services with sudo docker-compose up -d.