我正在尝试让 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
答案1
由于您已经将 GitLab 配置为使用/gitlab
带有
external_url "https://myhostname.com/gitlab"
/gitlab
(这是在 URI 前缀下托管任何比 SPA 更大的内容的唯一正确方法),在将请求传递到 GitLab 后端之前,您无需从请求 URI 中删除该前缀。rewrite ^/gitlab(/.*)$ $1 break;
从您的 nginx 配置中删除该行。是什么让您认为它是必要的?