首页 > 解决方案 > 用 apache 运行 gitlab

问题描述

我正在尝试使用 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>

标签: linuxgitapachegitlabubuntu-20.04

解决方案


当您使用 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

文件所需的更改。

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

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

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

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

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

  6. 将“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

重启阿帕奇:

sudo service apache2 restart

推荐阅读