0

背景

Ubuntu 15.10

Apache/2.4.10 (Ubuntu)

模块依赖项全部启用:

  • mod_rewrite
  • mod_proxy
  • mod_proxy_http

GitLab 社区版 8.0.3

GitLab docroot:/opt/gitlab/embedded/service/gitlab-rails/public

我以这种方式安装 GitLab:https ://about.gitlab.com/downloads/#ubuntu1404

问题

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

我让 GitLab 与捆绑的 nginx 一起运行(example-gitlab.com)

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

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

因此,exemple-gitlab.com 根据需要指向 GitLab,但 exemple-site.com 也指向 GitLab,所有其他 FQDN 也是如此。

解决方法

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

  • 禁用捆绑的 nginx 并使用 apache2 配置 gitlab(对我来说很难)
  • 将捆绑的 nginx 配置为 apache2 的反向代理(对我来说很难)

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

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

理解

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

我尝试禁用捆绑的 nginx/etc/gitlab/gitlab.rb

nginx['enable'] = false
# For GitLab CI, use the following:
ci_nginx['enable'] = false

添加www-datagitlab-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>

但是这个conf错误我的apache2:

~# 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.
4

2 回答 2

0

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

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

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

然后重新配置你的 gitlab 安装。

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

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

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

通过允许omnibus 管理nginx 配置,您不必在每次将服务从独角兽工作者移动到gitlab-git-http-server Go 服务器时都修改Web 服务器配置。Apache 将无缝代理对 nginx 的请求(在环回上),在更新期间将由综合总线自动保持最新。

于 2015-11-10T16:37:44.643 回答
0

Sorry I posted it on ServerFault and found the solution :

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 :)

于 2015-11-11T17:33:46.320 回答