0

I'm trying to make Gitlab work behind Nginx. my configs:

Nginx:

upstream gitlab-workhorse {
    server unix:/var/opt/gitlab/gitlab-workhorse/sockets/socket fail_timeout=0;
}

location /gitlab/ {
       rewrite ^/gitlab(/.*)$ $1 break;
       client_max_body_size 0;
       gzip off;
       proxy_read_timeout      300;
       proxy_connect_timeout   300;
       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-Ssl     on;
       proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
       proxy_set_header    X-Forwarded-Proto   $scheme;
       proxy_pass http://gitlab-workhorse;
}

/etc/gitlab/gitlab.rb:

external_url "https://myhostname.com/gitlab"
web_server['external_users'] = ['www-data']
nginx['enable'] = false
gitlab_workhorse['enable'] = true
gitlab_workhorse['listen_network'] = "unix"
gitlab_workhorse['listen_addr'] = "/var/opt/gitlab/gitlab-workhorse/sockets/socket"

at request to myhost.com/gitlab/users/sign_in I get "/users/sign_in" not found

if I change in gitlab configuration

external_url "https://myhostname.com/"

(without /gitlab path in the end) it starts to work but it's always redirects to the / of the server instead of /gitlab

1 Answers1

0

Since you already configured GitLab to use an URI prefix /gitlab with the

external_url "https://myhostname.com/gitlab"

(which is the only proper way to host anything bigger that a SPA under an URI prefix), you don't need to strip that /gitlab prefix from the request URI before passing the request to the GitLab backend. Remove that rewrite ^/gitlab(/.*)$ $1 break; line from your nginx config. What made you think it is needed at all?

Ivan Shatsky
  • 2,726
  • 2
  • 7
  • 19
  • apparently gitlab does not support relative urls – Stefan NovakDev Feb 22 '22 at 22:00
  • What makes you think so? The documentation [states](https://docs.gitlab.com/omnibus/settings/configuration.html#configure-a-relative-url-for-gitlab) exactly the opposite. Did you test your enviroment without the `rewrite` directive using the `external_url "https://myhostname.com/gitlab"`? – Ivan Shatsky Feb 22 '22 at 22:04
  • yeah thank you it actually helped! – Stefan NovakDev Feb 22 '22 at 23:47