Nginx

為 Gitlab 重寫 NGINX 位置

  • February 22, 2022

我試圖讓 Gitlab 在 Nginx 後面工作。我的配置:

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"

應 myhost.com/gitlab/users/sign_in 的請求,我得到“/users/sign_in”未找到

如果我更改 gitlab 配置

external_url "https://myhostname.com/"

(最後沒有/gitlab路徑)它開始工作,但它總是重定向到伺服器的 / 而不是 /gitlab

/gitlab由於您已經將 GitLab 配置為使用 URI 前綴

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

/gitlab(這是在 URI 前綴下託管比 SPA 更大的任何東西的唯一正確方法),在將請求傳遞到 GitLab 後端之前,您不需要從請求 URI 中刪除該前綴。rewrite ^/gitlab(/.*)$ $1 break;從您的 nginx 配置中刪除該行。是什麼讓你認為它是必要的?

引用自:https://serverfault.com/questions/1094499