使用Apache2 / Nginx的Gitlab 8.0.3

时间:2015-10-31 22:46:09

标签: ruby-on-rails apache gitlab gitlab-omnibus gitlab-8

背景

Ubuntu 15.10

Apache / 2.4.10(Ubuntu)

模块依赖关系全部启用:

  • mod_rewrite的
  • mod_proxy的
  • mod_proxy_http

GitLab Community Edition 8.0.3

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

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

问题

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

我使用捆绑的nginx运行GitLab(exemple-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或反向代理是如何工作的。

我尝试在/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:

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

2 个答案:

答案 0 :(得分:0)

最简单的方法是在环回地址上安装omnibus并配置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配置,您不必在每次将服务从unicorn worker移动到gitlab-git-http-server Go服务器时处理修改Web服务器配置。 Apache将无缝地代理请求到nginx(在环回上),这将在更新期间通过omnibus自动保持最新。

答案 1 :(得分:0)

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

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

  

我发现为什么apache2通过评论每一行而崩溃(damm日志是   无用)。

     

我只需要创建/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崩溃了,因为文件夹/目录丢失了......

     

所以现在gitlab正在开发域名,我的drupal也是这样:

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

如我所愿,特别是:)