更改默认的 Gitlab 端口
Changing the default Gitlab port
我已经按照此处所述通过 Omnibus 软件包在 CentOS 7(全新安装)上安装了最新的 Gitlab-CE (8.10):https://about.gitlab.com/downloads/#centos7
现在,我想更改可以访问 Gitlab 网络界面的默认端口。为此,我遵循了 http://docs.gitlab.com/omnibus/settings/nginx.html#change-the-default-port-and-the-ssl-certificate-locations 处的说明,即我包含了
external_url "http://127.0.0.1:8765"
在配置文件/etc/gitlab/gitlab.rb
中,然后用gitlab-ctl reconfigure && gitlab-ctl restart
更新了配置。
然而,当我导航到 http://127.0.0.1:8765
时,Gitlab 不断重定向到 http://127.0.0.1/users/sign_in
,即端口规范以某种方式被丢弃。然后,当我手动将浏览器中的 URL 更改为 http://127.0.0.1:8765/users/sign_in
时,它会正确显示登录页面,有趣的是,页面上的所有链接(例如,"Explore"、"Help")包含端口规范。
为了修复此行为,是否有必要在 /etc/gitlab/gitlab.rb
之外的其他地方指定端口?
除了external_url,文档还建议设置几个NGiNX代理headers:
By default, when you specify external_url
, omnibus-gitlab will set a few NGINX proxy headers that are assumed to be sane in most environments.
For example, omnibus-gitlab will set:
"X-Forwarded-Proto" => "https",
"X-Forwarded-Ssl" => "on"
(if you have specified https schema in the external_url
).
However, if you have a situation where your GitLab is in a more complex setup like behind a reverse proxy, you will need to tweak the proxy headers in order to avoid errors like The change you wanted was rejected or Can't verify CSRF token authenticity Completed 422 Unprocessable.
This can be achieved by overriding the default headers, eg. specify in /etc/gitlab/gitlab.rb
:
nginx['proxy_set_headers'] = {
"X-Forwarded-Proto" => "http",
"CUSTOM_HEADER" => "VALUE"
}
Save the file and reconfigure GitLab for the changes to take effect.
This way you can specify any header supported by NGINX you require.
OP ewcz confirms in the comments:
I just uncommented the default settings for nginx['proxy_set_headers']
in /etc/gitlab/gitlab.rb
(also, changing X-Forwarded-Proto
to http
and removing X-Forwarded-Ssl
) and suddenly it works!
问题在这里:https://gitlab.com/gitlab-org/gitlab-ce/issues/20131
解决方法:
将此行添加到 /etc/gitlab/gitlab.rb:
nginx['proxy_set_headers'] = { "X-Forward-Port" => "8080", "Host" => "<hostname>:8080" }
用您的值替换端口和主机名,然后以 root 身份或使用 sudo:
gitlab-ctl reconfigure
gitlab-ctl restart
它在 Debian 8.5 上对我有帮助,来自 gitlab repo 的 gitlab-ce。
我已经按照此处所述通过 Omnibus 软件包在 CentOS 7(全新安装)上安装了最新的 Gitlab-CE (8.10):https://about.gitlab.com/downloads/#centos7
现在,我想更改可以访问 Gitlab 网络界面的默认端口。为此,我遵循了 http://docs.gitlab.com/omnibus/settings/nginx.html#change-the-default-port-and-the-ssl-certificate-locations 处的说明,即我包含了
external_url "http://127.0.0.1:8765"
在配置文件/etc/gitlab/gitlab.rb
中,然后用gitlab-ctl reconfigure && gitlab-ctl restart
更新了配置。
然而,当我导航到 http://127.0.0.1:8765
时,Gitlab 不断重定向到 http://127.0.0.1/users/sign_in
,即端口规范以某种方式被丢弃。然后,当我手动将浏览器中的 URL 更改为 http://127.0.0.1:8765/users/sign_in
时,它会正确显示登录页面,有趣的是,页面上的所有链接(例如,"Explore"、"Help")包含端口规范。
为了修复此行为,是否有必要在 /etc/gitlab/gitlab.rb
之外的其他地方指定端口?
除了external_url,文档还建议设置几个NGiNX代理headers:
By default, when you specify
external_url
, omnibus-gitlab will set a few NGINX proxy headers that are assumed to be sane in most environments.For example, omnibus-gitlab will set:
"X-Forwarded-Proto" => "https",
"X-Forwarded-Ssl" => "on"
(if you have specified https schema in the
external_url
).However, if you have a situation where your GitLab is in a more complex setup like behind a reverse proxy, you will need to tweak the proxy headers in order to avoid errors like The change you wanted was rejected or Can't verify CSRF token authenticity Completed 422 Unprocessable.
This can be achieved by overriding the default headers, eg. specify in
/etc/gitlab/gitlab.rb
:
nginx['proxy_set_headers'] = {
"X-Forwarded-Proto" => "http",
"CUSTOM_HEADER" => "VALUE"
}
Save the file and reconfigure GitLab for the changes to take effect.
This way you can specify any header supported by NGINX you require.
OP ewcz confirms in the comments:
I just uncommented the default settings for
nginx['proxy_set_headers']
in/etc/gitlab/gitlab.rb
(also, changingX-Forwarded-Proto
tohttp
and removingX-Forwarded-Ssl
) and suddenly it works!
问题在这里:https://gitlab.com/gitlab-org/gitlab-ce/issues/20131 解决方法: 将此行添加到 /etc/gitlab/gitlab.rb:
nginx['proxy_set_headers'] = { "X-Forward-Port" => "8080", "Host" => "<hostname>:8080" }
用您的值替换端口和主机名,然后以 root 身份或使用 sudo:
gitlab-ctl reconfigure
gitlab-ctl restart
它在 Debian 8.5 上对我有帮助,来自 gitlab repo 的 gitlab-ce。