Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to enable harbor to use subpath like /sub/harbor? #21625

Open
cHenrique0 opened this issue Feb 12, 2025 · 1 comment
Open

How to enable harbor to use subpath like /sub/harbor? #21625

cHenrique0 opened this issue Feb 12, 2025 · 1 comment

Comments

@cHenrique0
Copy link

Hi,

I have a server and I installed Harbor 2.12.2 using docker-compose and looks fine. I can access using localhost:PORT and server_ip:PORT.
But I want to access Harbor using a subpath like mycompany.com/registry/harbor. I set up harbor.yml to use my DNS and relative URLs, and I set up a reverse proxy nginx below.

I can access mycompany.com/registry/harbor but I can't login, the endpoint returns 404. But, if I access mycompany.com.br:PORT I can login.

server {
    listen 80;

    server_name mycompany.com;

    location /registry/harbor/ {
        #sendfile off;

        proxy_pass         http://localhost:PORT/;
        proxy_redirect     off;
        proxy_http_version 1.1;

        proxy_set_header   Host              $http_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_max_temp_file_size 0;

        sub_filter        'href="/'          'href="/registry/harbor/';
        sub_filter        'src="/'           'src="/registry/harbor/';
        sub_filter        'action="/'        'action="/registry/harbor/';
        sub_filter        '"/c/'             '"/registry/harbor/c/';
        sub_filter        '"/service/token'  '"/registry/harbor/service/token';
        sub_filter        '"/api/'           '"/registry/harbor/api/';
        sub_filter        '"/v2/'            '"/registry/harbor/v2/';
        sub_filter_once   off;

        proxy_cookie_path / "/registry/harbor/";

        #this is the maximum upload size
        client_max_body_size       10m;
        client_body_buffer_size    128k;

        proxy_connect_timeout      90;
        proxy_send_timeout         90;
        proxy_read_timeout         90;
        proxy_request_buffering    off;
    }
}
@Vad1mo
Copy link
Member

Vad1mo commented Feb 13, 2025

Only the UI/portal will work on a path, the registry only works on domain.
The way it works for the registry part, has nothing to do with Harbor.

if you build the portal with:
NG_BUILD_ARGS: '--prod --base-href /admin-console/ --deploy-url /admin-console/'

Harbor Portal UI

The Angular-based portal code is itself unmodified. We performed changes to the Nginx configuration that serves the static HTML with the goal of allowing the application to work on the path different to domain.tld/. The desired path is now set to domain.tld/admin-console/.

Nginx Config Changes

  • Add rewrite rule, so that the application is present on /admin-console/
  • Set the base path in the index.html to /admin-console/

Code Snippet containing the changes lines

location /admin-console/ {
  rewrite ^/admin-console/(.*) /$1 break;
  try_files $uri $uri/ /index.html;
}

location = /index.html {
  add_header Cache-Control "no-store, no-cache, must-revalidate";
  sub_filter 'base href="/"' 'base href="/admin-console/"';
  sub_filter_once on;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants