Gitlab with apache2 and multiple websites

This tutorial assumes you have a Ubuntu 14.04 droplet on Digital Ocean with 2GB of RAM. If you use a smaller droplet with 1Gb of RAM, GitLab will run out of memory some times and crash. With a smaller droplet, it will simply not work.

The idea is to first install the Gitlab Omnibus package, install apache and configure gitlab to use the installed apache server instead of its default nginx server.

Gitlab Omnibus Install

First install all dependencies. Choose "Internet Site" during Postfix install. Then install the GitLab Omnibus package:

sudo apt-get install curl openssh-server ca-certificates postfix
curl | sudo bash
sudo apt-get install gitlab-ce

Modify the GitLab configuration file located on /etc/gitlab/gitlab.rb:

external_url "https://gitlab.<yourdomain>/"
gitlab_rails['gitlab_email_from'] = "gitlab@<yourdomain>"
gitlab_rails['gitlab_support_email'] = "gitlab-support@<yourdomain>"

Then run sudo gitlab-ctl reconfigure to reboot GitLab with the new settings.

After the last step, GitLab should be working properly. Visit your GitLab URL and login using the username root and password 5iveL!fe.

Installing apache2

Install apache2:

sudo apt-get update
sudo apt-get install apache2

sudo a2enmod proxy_http
sudo a2enmod proxy
sudo a2enmod rewrite
sudo a2enmod ssl
sudo a2enmod headers
sudo /etc/init.d/apache2 restart

If apache doesnt work with the error:

(98)Address already in use: AH00072: make_sock: could not bind to address [::]:80 - error

You can try to close other processes using port 80 with the commands:

# Find the process with
sudo lsof -i:80
# or
sudo netstat -ltnp | grep ':80'
# Then kill the process using its pid
sudo kill -9 1047

Another cause for this problem may be two directives in the apache configuration trying to bind to the same port.

grep Listen /etc/apache2/ports.conf

This command will show all lines that have the word "listen", including the port numbers. If there is more than one port 80 declaration in this file, remove one of them.

Configuring apache virtual hosts for a new a website

To configure a website domain with apache virtual hosts, duplicate the file /etc/apache2/sites-available/000-default.conf and rename it to something like Than change the files configurations:

<VirtualHost *:80>
  DocumentRoot /var/www/
  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

After creating the virtual host, add it to the enabled-sites and restart apache:

apache2 restart

Don't forget to create a virtual host for your gitlab domain.

Configuring gitlab to use apache2

In /etc/gitlab/gitlab.rb modify:

external_url ""
# Disable nginx
nginx['enable'] = false
# Give apache user privileges to listen to GitLab
web_server['external_users'] = ['www-data']

Create the Virtual Host file for GitLab on /etc/apache2/sites-available/gitlab.conf with the contents below, modifying the URLs:

<VirtualHost *:80>
  #This configuration has been tested on GitLab 6.0.0 and GitLab 6.0.1
  #Note this config assumes unicorn is listening on default port 8080.
  #Module dependencies
  #  mod_rewrite
  #  mod_proxy
  #  mod_proxy_http
  ServerSignature Off

  ProxyPreserveHost On

  # Ensure that encoded slashes are not decoded but left in their encoded state.
  AllowEncodedSlashes NoDecode

  <Location />
  # New authorization commands for apache 2.4 and up
  Require all granted


  #apache equivalent of nginx try files
  RewriteEngine on
  RewriteRule .*{REQUEST_URI} [P,QSA]

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

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


Then bind GitLab virtual host to enabled sites and restart apache:

sudo a2ensite gitlab
sudo service apache2 restart

Then run sudo gitlab-ctl reconfigure to reload GitLab configurations. If you need to restart the server, use the command sudo gitlab-ctl restart.

If by any chance you have to change the git-data file, its locate in /var/opt/gitlab/git-data.


Share this story