带有 Apache2/Nginx 的 Gitlab 8.0.3

Gitlab 8.0.3 with Apache2 / Nginx

背景

Ubuntu 15.10

Apache/2.4.10 (Ubuntu)

模块依赖全部启用:

GitLab 社区版 8.0.3

GitLab 文档根目录:/opt/gitlab/embedded/service/gitlab-rails/public

我是这样安装 GitLab 的:https://about.gitlab.com/downloads/#ubuntu1404

问题

在我的服务器上我有一个网站 运行 apache2 (example-site.com).

我有 GitLab 运行 捆绑的 nginx(示例-gitlab.com)

我有 1 个服务器、1 个 IP 和多个 FQDN。

像这样,我所有的域名都指向GitLab。

所以 exemple-gitlab.com 根据需要指向 GitLab 但 exemple-site.com 也指向 GitLab,所有其他 FQDN 也一样。

解决方法

我想我必须(并且我尝试过):

MAJ:实际上问题是 Apache 和 bundled-nginx 运行 在同一个 IP 上,同一个端口 (80)。而且我不想 运行 端口 81 或其他任何网站,只有端口 80。

我更喜欢将 apache2 用于我所有的 PHP 网站,我不介意 gitlab 使用 apache2 还是捆绑的 nginx,我想要的只是为我的每个网站使用我的所有 FQDN,而不是我的所有FQDN 重定向到 gitlab。

理解

我不明白综合或 rails 或反向代理是如何工作的。

我尝试在 /etc/gitlab/gitlab.rb

中禁用捆绑的 nginx
nginx['enable'] = false
# For GitLab CI, use the following:
ci_nginx['enable'] = false

www-data添加到gitlab-www组并修改:

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

并将修改后的 vhost.conf 添加到 apache2 我取自 https://gitlab.com/gitlab-org/gitlab-recipes/blob/master/web-server/apache/gitlab-apache24.conf

    <VirtualHost *:80>
    ServerName exemple-gitlab.com
    ServerSignature Off
    ProxyPreserveHost On

    AllowEncodedSlashes NoDecode

    <Location />
    Require all granted

    #Allow forwarding to gitlab-git-http-server
    ProxyPassReverse http://127.0.0.1:8181
    #Allow forwarding to GitLab Rails app (Unicorn)
    ProxyPassReverse http://127.0.0.1:8080
    ProxyPassReverse http://exemple-gitlab.com/
    </Location>

    #apache equivalent of nginx try files
    RewriteEngine on
    #Forward these requests to gitlab-git-http-server
    RewriteCond %{REQUEST_URI} ^/[\w\.-]+/[\w\.-]+/repository/archive.* [OR]
    RewriteCond %{REQUEST_URI} ^/api/v3/projects/.*/repository/archive.* [OR]
    RewriteCond %{REQUEST_URI} ^/[\w\.-]+/[\w\.-]+/(info/refs|git-upload-pack|git-receive-pack)$
    RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA]

    #Forward any other requests to GitLab Rails app (Unicorn)
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_URI} ^/uploads
    RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA,NE]

    # needed for downloading attachments
    /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

    # /var/log/apache2.
    LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
    ErrorLog  /var/log/apache2/logs/gitlab.example.com_error.log
    CustomLog /var/log/apache2/logs/gitlab.example.com_forwarded.log common_forwarded
    CustomLog /var/log/apache2/logs/gitlab.example.com_access.log combined env=!dontlog
    CustomLog /var/log/apache2/logs/gitlab.example.com.log combined

  </VirtualHost>

但是我的 apache2 这个 conf bug :

~# systemctl status apache2.service
● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2)
   Active: failed (Result: exit-code) since mar. 2015-11-10 15:41:08 CET; 1min 9s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 18315 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 18342 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)

nov. 10 15:41:08 vpsxxx.ovh.net apache2[18342]: * The apache2 configtest failed.
nov. 10 15:41:08 vpsxxx.ovh.net apache2[18342]: Output of config test was:
nov. 10 15:41:08 vpsxxx.ovh.net apache2[18342]: (2)No such file or directory: AH02291: Cannot access di...f:10
nov. 10 15:41:08 vpsxxx.ovh.net apache2[18342]: AH00014: Configuration check failed
nov. 10 15:41:08 vpsxxx.ovh.net apache2[18342]: Action 'configtest' failed.
nov. 10 15:41:08 vpsxxx.ovh.net apache2[18342]: The Apache error log may have more information.
nov. 10 15:41:08 vpsxxx.ovh.net systemd[1]: apache2.service: Control process exited, code=exited status=1
nov. 10 15:41:08 vpsxxx.ovh.net systemd[1]: Failed to start LSB: Apache2 web server.
nov. 10 15:41:08 vpsxxx.ovh.net systemd[1]: apache2.service: Unit entered failed state.
nov. 10 15:41:08 vpsxxx.ovh.net systemd[1]: apache2.service: Failed with result 'exit-code'.
Hint: Some lines were ellipsized, use -l to show in full.

最简单的方法是在环回地址上安装和配置 nginx,然后在前面使用 apache 作为反向代理。

只需重新启用 nginx 并将以下内容添加到您的 /etc/gitlab/gitlab.rb:

nginx['listen_addresses'] = ['127.0.1.1']

然后重新配置您的 git实验室安装。

然后,在您的 apache 站点配置中,使用类似于此的内容:

<VirtualHost *:80>
  ServerName exemple-gitlab.com
  ProxyPreserveHost On

  ProxyPass / http://127.0.1.1/
  ProxyPassReverse / http://127.0.1.1/
</VirtualHost>

通过允许 omnibus 管理 nginx 配置,您不必在每次他们将服务从 unicorn workers 移动到 gitlab-[=23= 时修改 Web 服务器配置]-http-server 去服务器。 Apache 将无缝地将请求代理到 nginx(在环回上),这将在更新期间通过 omnibus 自动保持最新。

抱歉,我将其发布在 ServerFault 上并找到了解决方案:

https://serverfault.com/questions/735270/gitlab-8-0-3-with-apache2-nginx/735273#735273

I found why apache2 crashed by commenting each line (damm logs were useless).

I just had to create /var/log/apache2/logs

 ErrorLog  /var/log/apache2/logs/gitlab.example.com_error.log
  CustomLog /var/log/apache2/logs/gitlab.example.com_forwarded.log common_forwarded
  CustomLog /var/log/apache2/logs/gitlab.example.com_access.log combined env=!dontlog
  CustomLog /var/log/apache2/logs/gitlab.example.com.log combined

apache2 was crashing because the folder/directory was missing ...

So now gitlab is working on is domain and my drupal too like this :

  • gitlab.com:80
  • drupal.com:80

Exactrly as I wanted :)