简体   繁体   中英

Gitlab 8.0.3 with Apache2 / Nginx

Background

Ubuntu 15.10

Apache/2.4.10 (Ubuntu)

Module dependencies are all enabled :

  • mod_rewrite
  • mod_proxy
  • mod_proxy_http

GitLab Community Edition 8.0.3

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

I install GitLab this way : https://about.gitlab.com/downloads/#ubuntu1404

Problem

On my server I have a website running with apache2 (exemple-site.com).

I have GitLab running with the bundled nginx (exemple-gitlab.com)

I have 1 server, 1 IP, and multiple FQDN.

Like this, all my domain names are pointing to GitLab.

So exemple-gitlab.com point to GitLab as wanted but exemple-site.com point to GitLab too, and all others FQDN too.

Ways of solution

I think I have to (and I tried) to :

  • Disable the bundled nginx and configure gitlab with apache2 (hard to do for me)
  • Configure the bundled nginx as a reverse proxy of apache2 (hard to do for me)

MAJ : in fact the problem is Apache and bundled-nginx run on the same IP with the same port (80). And I don't want to run a website on port 81 or whatever, only port 80.

I prefer to use apache2 for all my PHP websites and I don't mind if gitlab use apache2 or bundled nginx, all I want is using all my FQDN for each of my websites and not all my FQDN redirectinf to gitlab.

Understanding

I don't understand how omnibus or rails or reverse proxy work.

I tried disabling bundled nginx in /etc/gitlab/gitlab.rb

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

add www-data to gitlab-www group and modify :

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

and adding a modified vhost.conf to apache2 I take it from 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>

But this conf bug my 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.

The simplest way would be to have omnibus install and configure nginx on a loopback address, but then use apache in front as a reverse proxy.

Simply re-enable nginx and add the following to your /etc/gitlab/gitlab.rb :

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

Then reconfigure your gitlab installation.

Then, in your apache site configuration, use something similar to this:

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

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

By allowing omnibus to manage the nginx configuration, you don't have to deal with modifying the web server configuration every time they move a service from the unicorn workers to the gitlab-git-http-server Go server. Apache will seamlessly proxy requests to nginx (on the loopback) which will be automatically keep up to date by omnibus during updates.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM