Help us learn about your current experience with the documentation. Take the survey.

在 GitLab 中使用 Libravatar 服务

  • 层级:免费、专业、旗舰
  • 产品:GitLab 自管版

GitLab 默认支持 Gravatar 头像服务。

Libravatar 是另一项可将您的头像(个人资料图片)分发到其他网站的服务。Libravatar API 很大程度上基于 Gravatar,因此您可以切换到 Libravatar 头像服务,甚至是您自己的 Libravatar 服务器。

将 Libravatar 服务更改为您自己的服务

gitlab.yml 的 gravatar 部分中,按如下方式设置配置选项:

对于 Linux 包安装:

  1. 编辑 /etc/gitlab/gitlab.rb

    gitlab_rails['gravatar_enabled'] = true
    #### 对于 HTTPS
    gitlab_rails['gravatar_ssl_url'] = "https://seccdn.libravatar.org/avatar/%{hash}?s=%{size}&d=identicon"
    #### 对于 HTTP,请改用此行
    # gitlab_rails['gravatar_plain_url'] = "http://cdn.libravatar.org/avatar/%{hash}?s=%{size}&d=identicon"
  2. 要应用更改,请运行 sudo gitlab-ctl reconfigure

对于源码编译安装:

  1. 编辑 config/gitlab.yml

      gravatar:
        enabled: true
        # default: https://www.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon
        plain_url: "http://cdn.libravatar.org/avatar/%{hash}?s=%{size}&d=identicon"
        # default: https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=identicon
        ssl_url: https://seccdn.libravatar.org/avatar/%{hash}?s=%{size}&d=identicon"
  2. 保存文件,然后重启 GitLab 以使更改生效。

将 Libravatar 服务设置为默认(Gravatar)

对于 Linux 包安装:

  1. /etc/gitlab/gitlab.rb 中删除 gitlab_rails['gravatar_ssl_url']gitlab_rails['gravatar_plain_url']
  2. 要应用更改,请运行 sudo gitlab-ctl reconfigure

对于源码编译安装:

  1. config/gitlab.yml 中删除 gravatar: 部分。
  2. 保存文件,然后重启 GitLab 以应用更改。

禁用 Gravatar 服务

要禁用 Gravatar(例如,为了禁止第三方服务),请完成以下步骤:

对于 Linux 包安装:

  1. 编辑 /etc/gitlab/gitlab.rb

    gitlab_rails['gravatar_enabled'] = false
  2. 要应用更改,请运行 sudo gitlab-ctl reconfigure

对于源码编译安装:

  1. 编辑 config/gitlab.yml

      gravatar:
        enabled: false
  2. 保存文件,然后重启 GitLab 以应用更改。

您自己的 Libravatar 服务器

如果您运行自己的 Libravatar 服务,配置中的 URL 会不同,但您必须提供相同的占位符,以便 GitLab 能够正确解析 URL。

例如,您在 https://libravatar.example.com 上托管了一项服务,那么您必须在 gitlab.yml 中提供的 ssl_url 是:

https://libravatar.example.com/avatar/%{hash}?s=%{size}&d=identicon

缺失图像的默认 URL

Libravatar 支持不同的图像集,用于处理在 Libravatar 服务上找不到的用户电子邮件地址的头像。

要使用 identicon 之外的图像集,请将 URL 中的 &d=identicon 部分替换为另一个受支持的图像集。例如,您可以使用 retro 图像集,这种情况下 URL 将如下所示:ssl_url: "https://seccdn.libravatar.org/avatar/%{hash}?s=%{size}&d=retro"

Microsoft Office 365 的使用示例

如果您的用户是 Office 365 用户,则可以使用 GetPersonaPhoto 服务。 此服务需要登录,因此此用例在企业安装中最有用,因为所有用户都可以访问 Office 365。

gitlab_rails['gravatar_plain_url'] = 'http://outlook.office.com/owa/service.svc/s/GetPersonaPhoto?email=%{email}&size=HR120x120'
gitlab_rails['gravatar_ssl_url'] = 'https://outlook.office.com/owa/service.svc/s/GetPersonaPhoto?email=%{email}&size=HR120x120'