How to Use Apache Instead of Built-in NGINX in Gitlab CE

Overview

How to Use Apache Instead of Built-in NGINX in Gitlab CE

Issue

  • I wanted to setup additional sites on the server using Apache, but now port 80 was already bound to by GitLab’s built-in Nginx web server.

Stop Gitlab Services

$ gitlab-ctl stop
ok: down: logrotate: 0s, normally up
ok: down: postgresql: 1s, normally up
ok: down: redis: 0s, normally up
ok: down: nginx: 0s, normally up
ok: down: sidekiq: 0s, normally up
ok: down: unicorn: 0s, normally up

Disable built-in NGINX

$ vim /etc/gitlab/gitlab.rb

# Uncomment the web server username and group settings, and set both to Apache.
web_server['username'] = 'apache'
web_server['group'] = 'apache'

# In the next section, “GitLab Nginx,” uncomment the first line and set it to false.
nginx['enable'] = false

Reconfigure GitLab

# Avoid postgresql is not running errors.
$ gitlab-ctl start postgresql
$ gitlab-ctl reconfigure

Setup Apache

<VirtualHost *:80>
  ServerName git.example.com
  DocumentRoot /opt/gitlab/embedded/service/gitlab-rails/public

  ProxyPreserveHost On
  AllowEncodedSlashes Off

  <Location />
    Order deny,allow
    Allow from all
    ProxyPassReverse http://127.0.0.1:8080
    ProxyPassReverse http://git.example.com/
  </Location>

  RewriteEngine on
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA]
</VirtualHost>

Restart Apache

$ httpd -t && sudo service httpd restart

Start Gitlab Services

$ gitlab-ctl restart
ok: run: logrotate: (pid 22857) 0s
ok: run: postgresql: (pid 22860) 1s
ok: run: redis: (pid 22868) 0s
ok: run: sidekiq: (pid 22872) 1s
ok: run: unicorn: (pid 22876) 0s

NOTE: NGINX should not be listed anymore.



Newsletter

Get updated when I create new content.
Unsubscribe whenever. Never any spam.

Note

I'm Tama. I turn down every ad, affiliate, and sponsor request I get. I write free resources that help people. If you enjoy my content, please consider supporting what I do.

Support my work