Reverse-proxying relative URL to root URL results in 404 errorpage

Hi,

since nobody picked up my posted issue (Reverse Proxying relative URL to root URL results in 404 errorpage (#37028) · Issues · GitLab.org / GitLab FOSS · GitLab) I hope to find help or hints from this forum

Our GitLab (community version) instance runs on an internal server as https://internal.gitlab.server while its external URL is https://our.company.website/gitlab/. In-between sits a proxy. However when we configure the system according to Configuration options for Linux package installations | GitLab, then accessing the external URL results in a 404 error.

The current workaround solution consists of external_url being https://internal.gitlab.server with the proxy being configured for URL rewriting:

  <Location /gitlab/>
    # SetOutputFilter INFLATE;proxy-html;DEFLATE
    # LogLevel debug
    ProxyHTMLEnable   on
    ProxyHTMLExtended on
    ProxyHTMLMeta     on

    ProxyHTMLLinks  a          href
    ProxyHTMLLinks  area       href
    ProxyHTMLLinks  link       href
    ProxyHTMLLinks  img        src longdesc usemap
    ProxyHTMLLinks  object     classid codebase data usemap
    ProxyHTMLLinks  q          cite
    ProxyHTMLLinks  blockquote cite
    ProxyHTMLLinks  ins        cite
    ProxyHTMLLinks  del        cite
    ProxyHTMLLinks  form       action
    ProxyHTMLLinks  input      src usemap
    ProxyHTMLLinks  head       profile
    ProxyHTMLLinks  base       href
    ProxyHTMLLinks  script     src for
    ProxyHTMLLinks  meta       content

    ProxyHTMLURLMap https://internal.gitlab.server:443/ /gitlab/
    ProxyHTMLURLMap https://internal.gitlab.server/     /gitlab/
    ProxyHTMLURLMap http://internal.gitlab.server:80/   /gitlab/
    ProxyHTMLURLMap /                                   /gitlab/

    ProxyPass          https://internal.gitlab.server:443/
    ProxyPassReverse   https://internal.gitlab.server:443/
    ProxyPass          https://internal.gitlab.server/
    ProxyPassReverse   https://internal.gitlab.servere/
    ProxyPassReverse   https://our.internal.proxy/
    ProxyPassReverse   https://our.company.website/
  </Location>

This is ugly, badly maintainable and still leaves us with lots of broken links (icons images) and non-working functionality (no project graph, cannot add users to projects ecc. ecc.) when we use GitLab through https://our.company.website/gitlab/. However it works when accessing GitLab through https://internal.gitlab.server but this is not possible for external coworkers…

If you have solved this problem yourself or if you have an idea on how to properly configure this setup, then your input is highly appreciated :slight_smile:

Cheers
frank

Configure reverse-proxying with a relative URL in GitLab, you can follow these steps
Update your GitLab configuration file (gitlab.rb) to include the following settings…

external_url 'https://our.company.website/gitlab/'
relative_url_root '/gitlab'

Save and restart GitLab.
Configure your proxy server “Nginx”.

location /gitlab/ {
  proxy_pass http://internal.gitlab.server/;
  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;
}

Save and restart to the apply the changes.

Configuring GitLab with the relative_url_root option and setting up the proxy server accordingly, you should be able to access GitLab through the external URL (https://our.company.website/gitlab/) while maintaining proper functionality and avoiding broken links. Use a service like RedirectChecker.com to gets its detail redirect chain and its status code.