counter create hit

Installing GitLab on existing Apache Server for Ubuntu

GitLab works under built-in Nginx web server engine by default. Therefore, if you already have an existing web server, you may need some extra work to use both your existing websites and GitLab at the same time. The easiest way is to assign different ports on two different servers, but it may not be the good way because visitors have to remember the specified port every time they connect. The article presents the way to add GitLab on existing Apache server using reverse proxy approach.

Step 1: Install GitLab

To install GitLab, please type the following commands to install gitlab-ce:

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

If this is the only and first website for your server, then you can just use it without any issues. However, if you already have an existing website, you will eventually find out that your existing website is replaced by GitLab you have just installed. If you have an existing Apache web server, please restart your Apache server by using the following command, and check your website again:

sudo service apache2 restart

The solution for the presented issue will be introduced in the following section.

Step 2: Modify GitLab configuration

The GitLab configuration file in Ubuntu is "/etc/gitlab/gitlab.rb". Type the following command to edit the configuration file:

sudo nano /etc/gitlab/gitlab.rb

Now, edit the following lines:

# Change GitLab port (any unused port is ok.)
external_url ''

Save the file, and run the following command:

sudo gitlab-ctl reconfigure

Step 3: Configure Apache to use GitLab using reverse proxy

Before presenting the main entry, please make sure that you have a domain or subdomain url for applying on GitLab url. In this article, we assume that you have a url, "" for GitLab, as an example.

Now, please make sure proxy_http module is enabled on Apache engine. You can enable the module using the following command:

sudo a2enmod proxy_http

Please create an Apache site configuration for gitlab as follows:

cd /etc/apache2/sites-available/
sudo touch gitlab.conf
sudo nano gitlab.conf

Now, add the VirtualHost entry as follows:

<VirtualHost *:80>

  ProxyRequests off
  ProxyPass /
  ProxyPassReverse /

Now, enable the gitlab website configuration using the following command:

sudo a2ensite gitlab
sudo service apache2 restart

Step 4: Resolve an issue of displaying wrong repository url on GitLab

Because the actual GitLab is running under the bundled Nginx server, the repository url displayed on GitLab webpage may be wrong (i.e., and inaccessible from the actual client. You can resolve this issue by modifying the following configuration file:

sudo nano /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

Original configuration:

## Web server settings (note: host is the FQDN, do not include http://)
port: 14500
https: false

Modify the configuration as follows:

## Web server settings (note: host is the FQDN, do not include http://)
port: 80
https: false

Now, restart gitlab using the following command:

sudo gitlab-ctl restart

You can now connect to GitLab using through the Apache server. Please note that the configuration will reset to if you use the command gitlab-ctl reconfigure. Therefore, you have to modify the setting again if you reconfigure GitLab.

Note 1: If you want to use https…

If you want to setup GitLab using https, you need some extra configurations. Assuming that you already have a valid certificate, key, and root ca, please follow the instruction below.

Modify GitLab settings

First, modify /etc/gitlab/gitlab.rb as follows:

# Change GitLab port (any unused port is ok.)
external_url ''

# GitLab Nginx #
nginx['ssl_certificate'] = "/path/to/certificate.crt"
nginx['ssl_certificate_key'] = "/path/to/certificate_key.key"

Then, reconfigure GitLab by using the following command:

sudo gitlab-ctl reconfigure

Now, modify /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml as follows:

## Web server settings (note: host is the FQDN, do not include http://)
port: 443
https: true

Finally, restart gitlab-ctl by typing the following command:

sudo gitlab-ctl restart

Modify Apache settings

To configure https reverse proxy on Apache, modify the /etc/apache2/sites-available/gitlab.conf on Apache as follows:

<VirtualHost *:80>
  Redirect permanent /

<VirtualHost *:443>

  # Certificate
  SSLEngine on
  SSLCertificateFile /path/to/certificate.crt
  SSLCertificateKeyFile /path/to/certificate_key.key
  SSLCertificateChainFile /path/to/certificate_ca.crt

  # Proxy
  SSLProxyEngine on
  SSLProxyVerify none
  SSLProxyCheckPeerCN off
  SSLProxyCheckPeerName off
  SSLProxyCheckPeerExpire off

  ProxyPass /
  ProxyPassReverse /

Now, type the following command to restart Apache, and you can not use GitLab through https.

sudo service apache2 restart

Note 2: if you want to limit access by IP…

If you want to limit GitLab access by IP, add the following statement on gitlab.conf:

<Proxy *>
  Order Deny,Allow
  Deny from all
  Allow from your_ip_address


As presented above, you can use GitLab with existing Apache server setting up reverse proxy on Apache and connect to bundled Nginx engine on GitLab. I think there may be other ways to configure Apache with GitLab, and the approach we presented is one of the way. Please let us know if there is a better way to configure it.


[1], "[SOLVED] Setting up Gitlab on Ubuntu 14.04 with Apache2 without owning a domain name," GitLab Forum, 27-Apr-2015. [Online]. Available:
[2], "js, and css not appearing after installing gitlab," Superuser, 19-Nov-2015. [Online]. Available:
[3] Goedecke, "Setup GitLab on Debian 7 with existing Apache WebServer," GitLab Forum, 17-Sep-2015. [Online]. Available:
[4], "Gitlab in a subdirectory with apache and passenger,", 29-Jul-2013. [Online]. Available:
[5] Tully, "Running GitLab from a subdirectory on Apache,", 23-Aug-2012. [Online]. Available:
[6], "Redmine in a subdirectory,", 03-Sep-2008. [Online]. Available:

2 comments on "Installing GitLab on existing Apache Server for Ubuntu"

  1. you have got a excellent weblog here! would you ljke to
    have invite posts on my site?

    • Hello, Brigida.
      I checked your website, but I was unable to understand the meaning of “invite posts”. I would appreciate if you give me the details of it. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *