Setting up Gitlab/CI with Apache

When I setup our Gitlab/CI server I could find a fair amount of info on using Apache with Gitlab and vhost but not much on vhost config for the CI.

I have got it working so wanted to share the config files I am using. Am open to any feedback on improvements to these config files.

Changes made to gitlab.rb for these to work

  • Set unicorn
    – unicorn[‘listen’] = ‘127.0.0.1’ unicorn[‘port’] = 8080
  • Set external users to the one used by Apache
    – web_server[‘external_users’] = [‘www-data’]
  • Disable nginx
    – nginx[‘enable’] = false

Gitlab vhost config:

<VirtualHost *:80>
  ServerName mygitlab.mydomain.com
  ServerAlias mygitlab
  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

    ProxyPassReverse http://127.0.0.1:8080
    ProxyPassReverse http://mygitlab.mydomain.com/
  </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
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA]

  # needed for downloading attachments
  DocumentRoot /var/opt/gitlab

  #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

  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
  ErrorLog  /var/log/apache2/gitlab_error.log
  CustomLog /var/log/apache2/gitlab_forwarded.log common_forwarded
  CustomLog /var/log/apache2/gitlab_access.log combined env=!dontlog
  CustomLog /var/log/apache2/gitlab.log combined

</VirtualHost>

Gitlab-CI vhost confg:

<VirtualHost *:80>
  ServerName myci.mydomain.com
  ServerAlias myci
  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

    ProxyPassReverse http://127.0.0.1:8181
    ProxyPassReverse http://myci.mydomain.com/
  </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
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA]

  # needed for downloading attachments
  DocumentRoot /var/opt/gitlab/gitlab-ci

  #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

  LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
  ErrorLog  /var/log/apache2/ci_error.log
  CustomLog /var/log/apache2/ci_forwarded.log common_forwarded
  CustomLog /var/log/apache2/ci_access.log combined env=!dontlog
  CustomLog /var/log/apache2/ci.log combined

</VirtualHost>