用 apache 运行 gitlab

Posted

技术标签:

【中文标题】用 apache 运行 gitlab【英文标题】:run gitlab with apache 【发布时间】:2021-07-09 16:31:36 【问题描述】:

我正在尝试使用 apache 在 ubuntu 20.04 LTS 上运行 gitlab。 我按照官方安装指南:https://about.gitlab.com/install/#ubuntu

当我在 git.domain.de 上打开我的 gitlab 时,我只看到“正在部署”错误页面。 我在日志中看到以下错误:

[proxy:error] [pid 2267591:tid 139801344845568] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8080 (*) failed
[proxy_http:error] [pid 2267591:tid 139801344845568] [client 91.64.235.xxx:51508] AH01114: HTTP: failed to make connection to backend: 127.0.0.1
[proxy:error] [pid 2267592:tid 139801344845568] (111)Connection refused: AH00957: HTTP: attempt to connect to 127.0.0.1:8080 (*) failed
[proxy_http:error] [pid 2267592:tid 139801344845568] [client 91.64.235.xxx:51513] AH01114: HTTP: failed to make connection to backend: 127.0.0.1, referer: http://git.domain.de/

我的 apache 站点可用配置如下所示:

<VirtualHost *:80>

  ServerName git.domain.de
  ServerSignature Off

  ProxyPreserveHost On
  AllowEncodedSlashes NoDecode

  <Location />
  Require all granted

  ProxyPassReverse http://127.0.0.1:8080
  ProxyPassReverse http://git.domain.de
  </Location>

  RewriteEngine on
  RewriteCond %DOCUMENT_ROOT/%REQUEST_FILENAME !-f
  RewriteRule .* http://127.0.0.1:8080%REQUEST_URI [P,QSA]

  # needed for downloading attachments
  DocumentRoot /opt/gitlab/embedded/service/gitlab-rails/public

  #Set up apache error documents, if back end goes down (i.e. 503 error) then a maintenance/deploy page is thrown up.
  ErrorDocument 404 /404.html
  ErrorDocument 422 /422.html
  ErrorDocument 500 /500.html
  ErrorDocument 503 /deploy.html

...

</VirtualHost>

【问题讨论】:

对此有什么想法吗? 你做了docs.gitlab.com/omnibus/settings/…和docs.gitlab.com/omnibus/settings/… 这里的答案看起来是一个很好的资源。不过,我对您的问题有一个疑问……您为什么要这样做? nginx 速度更快,可能是 Apache 的继任者。 我很想使用 Nginx,但不幸的是我不知道如何做到这一点。当我尝试使用 Nginx 和 apache 时,我总是遇到端口已经在使用中的问题。 【参考方案1】:

当您使用 Apache 运行 gitlab 时,您需要更多的配置步骤。

安装依赖项

sudo apt-get install apache2
sudo apt-get install curl openssh-server ca-certificates postfix

配置 Gitlab 以使用 Apache

sudo vim /etc/gitlab/gitlab.rb

文件所需的更改。

    将“nginx['enable'] = true”改为“nginx['enable'] = false”

    将“web_server['external_users'] = []”更改为“web_server['external_users'] = ['www-data']”

    将“gitlab_rails['trusted_proxies']”更改为您的 Web 服务器 IP 地址。例如gitlab_rails['trusted_proxies'] = ['10.128.0.2']

    将 "gitlab_workhorse['listen_network'] = "unix" 更改为 gitlab_workhorse['listen_network'] = "tcp"

    将 gitlab_workhorse['listen_addr'] = "/var/opt/gitlab/gitlab-workhorse/socket" 更改为 gitlab_workhorse['listen_addr'] = "127.0.0.1:8181"

    将“unicorn['port'] = 8080”改为“unicorn['port'] = 8082”

更新 Gitlab 端口 创建或编辑文件:

vim /etc/default/gitlab

在下方添加/更新,

gitlab_workhorse_options="-listenUmask 0 -listenNetwork tcp -listenAddr 127.0.0.1:8181 -authBackend http://127.0.0.1:8082"

重新加载新的 Gitlab 配置

sudo gitlab-ctl reconfigure

启用 Apache mod_proxy 和 mod_rewrite

sudo a2enmod proxy; 
sudo a2enmod rewrite; 
sudo a2enmod proxy_http;

为 Gitlab 创建 Apache 配置

sudo vim /etc/apache2/sites-available/gitlab.conf

启用 apache 配置:

sudo a2ensite gitlab

重启apache:

sudo service apache2 restart

【讨论】:

我什么都做了,但没有任何改变。还是同样的错误。 Gitlab 的 Apache Config 应该是什么样子的? 连接被拒绝:AH00957:HTTP:尝试连接到 127.0.0.1:8080 (*) 失败 @webGuy 你是否在 apache 配置中打开了“Listen 8080”端口? 我的 apache 站点可用配置看起来与 postet 完全一样 查看以下链接

以上是关于用 apache 运行 gitlab的主要内容,如果未能解决你的问题,请参考以下文章

如何让 Gitlab 6.5 在 Apache 2.4 代理下显示其图标?

如何在运行作业之前使用用户界面向 gitlab 作业添加选项?

8080 端口上的 Gitlab

Gitlab 配置问题:: NGINX 独角兽端口冲突

没有权限运行下游管道的用户如何从上游管道触发运行 GitLab 下游管道

GitLab 仅手动而不是自动运行管道