1

我有我的 gitlab 在本地工作,但不知何故我无法从外部访问它。无法弄清楚问题所在。我正在运行 Debian 8 系统。

当前配置文件:

/etc/gitlab/gitlab.rb

gitlab_url = "http://127.0.0.1:9999"
external_url "http://gitlab.example.ee"

gitlab_rails['gitlab_host'] = "gitlab.example.ee"
gitlab_rails['gitlab_email_from'] = "gitlab@example.ee"
gitlab_rails['internal_api_url'] = "http://localhost:9999"

web_server['external_users'] = ['www-data']

unicorn['port'] = "9999"
nginx['enable'] = false

apache vhost (/etc/apache2/sites-available/gitlab.conf)

<VirtualHost *:9999>
ServerAdmin info@example.ee
DocumentRoot /opt/gitlab/embedded/service/gitlab-rails/public
ServerName gitlab.example.ee
ServerAlias gitlab.example.ee
ProxyPreserveHost On

<Location />

    Order deny,allow
    Allow from all
    Options FollowSymLinks
    Require all granted

    ProxyPassReverse http://localhost:9999/
    ProxyPassReverse http://gitlab.example.ee/
</Location>

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule .* http://localhost:9999%{REQUEST_URI} [P,QSA]

ErrorDocument 404 /404.html
ErrorDocument 422 /422.html
ErrorDocument 500 /500.html
ErrorDocument 503 /deploy.html

LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
ErrorLog  /${APACHE_LOG_DIR}/gitlab.error.log
CustomLog /${APACHE_LOG_DIR}/gitlab.forwarded.log common_forwarded
CustomLog /${APACHE_LOG_DIR}/gitlab.access.log combined env=!dontlog
CustomLog /${APACHE_LOG_DIR}/gitlab.log combined
</VirtualHost>
4

2 回答 2

0

我意识到这个问题已经有几年了,但我最近一直在玩类似的设置(但没有安装 ISPConfig)。为可能遇到此问题的其他人投入我的 2 美分(这是我第一次回答,所以请放轻松)。

注意op 没有指定正在使用的 GitLab 的版本。较新版本的 GitLab 可能正在使用较新版本的,gitlab.rb所以我不确定这是否会有所作为。

注 2我在此站点上直接从 GitLab 找到了大量信息:https ://docs.gitlab.com/omnibus/settings/nginx.html#using-a-non-bundled-web-server 。这基本上是一个复制和粘贴,但我将自己的笔记扔进去,以帮助解决我作为一个完整的 n00b 遇到问题的地方。

  1. 禁用捆绑的 Nginx

套装中/etc/gitlab/gitlab.rb

nginx['enable'] = false
  1. 设置非捆绑网络服务器用户的用户名

默认情况下,omnibus-gitlab 对外部网络服务器用户没有默认设置,您必须在配置中指定它。对于 Debian/Ubuntu,默认用户是www-dataApache/Nginx,而对于 RHEL/CentOS,Nginx 用户是 nginx。

注意:确保您首先安装了 Apache/Nginx,以便创建 webserver 用户,否则在重新配置时omnibus 将失败。

例如,假设网络服务器用户是 www-data。在 /etc/gitlab/gitlab.rb 设置:

web_server['external_users'] = ['www-data']

注意:此设置是一个数组,因此您可以指定多个用户添加到 gitlab-www 组。 个人注意:请注意这里的单引号和数组。在开发过程中,我多次重建了我的 gitlab 服务器并输入了一个字符串或一个数组,两者都会失败。Chef 脚本将使用此值为其​​内部目录设置文件权限,因此如果不正确,Apache 将无法写入文件。

运行sudo gitlab-ctl reconfigure以使更改生效。

注意:如果您使用 SELinux 并且您的 Web 服务器在受限制的 SELinux 配置文件下运行,您可能必须放松对 Web 服务器的限制。

*注意:确保 webserver 用户对外部 web-server 使用的所有目录具有正确的权限,否则在读取上游错误时会收到 failed (XX: Permission denied)。

  1. 将非捆绑的网络服务器添加到受信任的代理列表中(可选:仅当您的网络服务器与您的 gitlab 实例位于不同的机器上时才需要这样做)

通常,omnibus-gitlab 将可信代理列表默认为捆绑 NGINX 的 real_ip 模块中配置的内容。

对于非捆绑的网络服务器,需要直接配置列表,如果它与 GitLab 不在同一台机器上,则应包括您的网络服务器的 IP 地址。否则,用户将显示为从您的 Web 服务器的 IP 地址登录。

gitlab_rails['trusted_proxies'] = [ '192.168.1.0/24', '192.168.2.1', '2001:0db8::/32' ]
  1. (可选)如果使用 Apache,请设置正确的 gitlab-workhorse个人注意:我相信这是操作问题中缺少的配置。

注意:以下值是在 GitLab 8.2 中添加的,请确保您安装了最新版本。

Apache 无法连接到 UNIX 套接字,而是需要连接到 TCP 端口。要允许 gitlab-workhorse 监听 TCP(默认端口8181),请编辑/etc/gitlab/gitlab.rb

gitlab_workhorse['listen_network'] = "tcp"
gitlab_workhorse['listen_addr'] = "127.0.0.1:8181"

运行sudo gitlab-ctl reconfigure以使更改生效。

  1. 下载正确的 Web 服务器配置

转到GitLab 配方存储库并在您选择的网络服务器目录中查找综合配置。确保选择正确的配置文件,具体取决于您是否选择使用 SSL 服务 GitLab。您唯一需要更改的是带有您自己的 FQDN 的 YOUR_SERVER_FQDN,如果您使用 SSL,则为您的 SSL 密钥当前所在的位置。您可能还需要更改日志文件的位置。

为了完整起见,这里是一个没有 SSL 配置的 Apache v2.4 配置示例:阅读评论:如果您按照我上面的说明进行操作,在第 4 步中 gitlab_workhorse 已经配置为侦听 tcp 而不是 unix socket 以便可以忽略该行。 不要忽略模块依赖关系!这些是 Apache 能够将请求代理到您的 gitlab 实例所必需的。在 Ubuntu 上(我使用的是 Ubuntu Server 16.04.4,但我相信大多数其他 Ubuntu 版本的反应相同),这些模块可以使用sudo a2enmod rewrite proxy proxy_http.

# This configuration has been tested on GitLab 8.2
# Note this config assumes unicorn is listening on default port 8080 and
# gitlab-workhorse is listening on port 8181. To allow gitlab-workhorse to
# listen on port 8181, edit or create /etc/default/gitlab and change or add the following:
#
# gitlab_workhorse_options="-listenUmask 0 -listenNetwork tcp -listenAddr 127.0.0.1:8181 -authBackend http://127.0.0.1:8080"
#
#Module dependencies
# mod_rewrite
# mod_proxy
# mod_proxy_http
<VirtualHost *:80>
  ServerName YOUR_SERVER_FQDN
  ServerSignature Off

  ProxyPreserveHost On

  # Ensure that encoded slashes are not decoded but left in their encoded state.
  # http://doc.gitlab.com/ce/api/projects.html#get-single-project
  AllowEncodedSlashes NoDecode

  <Location />
    # New authorization commands for apache 2.4 and up
    # http://httpd.apache.org/docs/2.4/upgrading.html#access
    Require all granted

    #Allow forwarding to gitlab-workhorse
    ProxyPassReverse http://127.0.0.1:8181
    ProxyPassReverse http://YOUR_SERVER_FQDN/
  </Location>

  # Apache equivalent of nginx try files
  # http://serverfault.com/questions/290784/what-is-apaches-equivalent-of-nginxs-try-files
  # http://stackoverflow.com/questions/10954516/apache2-proxypass-for-rails-app-gitlab
  RewriteEngine on

  #Forward all requests to gitlab-workhorse except existing files like error documents
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
  RewriteCond %{REQUEST_URI} ^/uploads/.*
  RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA,NE]

  # needed for downloading attachments
  DocumentRoot /home/git/gitlab/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 502 /502.html
  ErrorDocument 503 /503.html

  # It is assumed that the log directory is in /var/log/httpd.
  # For Debian distributions you might want to change this to
  # /var/log/apache2.
  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
  ErrorLog /var/log/httpd/logs/YOUR_SERVER_FQDN_error.log
  CustomLog /var/log/httpd/logs/YOUR_SERVER_FQDN_forwarded.log common_forwarded
  CustomLog /var/log/httpd/logs/YOUR_SERVER_FQDN_access.log combined env=!dontlog
  CustomLog /var/log/httpd/logs/YOUR_SERVER_FQDN.log combined

</VirtualHost>

此配置文件不适用于简单的复制和粘贴!

  1. 查找“YOUR_SERVER_FQDN”并将其替换为您的 gitlab 实例的完全限定域名。根据操作员的问题,这将是,但应该基本上与文件http://gitlab.example.ee中的值匹配。external_urlgitlab.rb

  2. 查找并用“apache”替换“httpd”。该配置在设计时并未考虑到 Ubuntu 服务器,相应的目录称为“apache”。我假设你也可以使用 ${APACHE_LOG_DIR},但我自己没有测试过。

对于基本设置,这应该可以正常工作。我强烈建议研究使用 SSL 设置(可以在提供的链接中找到文档)。即使您不需要安全设置(也许这是一个内部服务器),综合中的其他功能,如 Mattermost,在没有启用 SSL(而不是使用自签名证书)的情况下也容易引发错误。

于 2018-04-03T17:28:49.363 回答
0

您可能需要确保您的防火墙没有阻止与端口 9999 的连接。在 Ubuntu 上,您可能需要执行以下操作:

sudo ufw allow 9999/tcp
于 2015-12-27T14:16:20.067 回答