I installed GitLab CE using the Omnibus package on a new CentOS 6 server. Since I had nothing else on the server at that time, everything GitLab setup and configured was sufficient. Later, however, 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.
What I really wanted to do is disable the built-in Nginx server and just use my self-managed Apache installation. Here’s how to do just that.
1. Stop GitLab services
This will shutdown GitLab while we work on it.
$ 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
2. Disable built-in Nginx
If you’re using GitLab out of the box, your GitLab configuration file should be located in /etc/gitlab
. Go ahead and edit it.
vi /etc/gitlab/gitlab.rb
Scroll all the way down to the “GitLab Web Server” header. You can jump there by searching for “Web”: hit the forward slash on your keyboard (/
), type in Web
and hit ENTER.
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
3. Reconfigure GitLab
This will parse your updated GitLab configuration file and disable Nginx.
$ gitlab-ctl reconfigure
4. Add virtual host for GitLab to Apache
Create a new virtual host file for GitLab with the following directives (based on a GitLab recipe). Update git.domain.com
to the domain you were using for GitLab.
<VirtualHost *:80> ServerName git.domain.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.domain.com/ </Location> RewriteEngine on RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule .* http://127.0.0.1:8080%{REQUEST_URI} [P,QSA] </VirtualHost>
I turned AllowEncodedSlashes
off because I couldn’t find any URLs in GitLab that needed this, however, if you have issues with certain URLs not loading, try to set that directive to NoDecode
.
AllowEncodedSlashes NoDecode
Note that your version of Apache would need to be 2.2.18 or later— NoDecode
didn’t exist before that.
Restart or start Apache once the virtual host file is in place.
service httpd reload
5. Start GitLab services
Since we turned GitLab off earlier, let’s boot it back up.
$ gitlab-ctl start 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 that Nginx should not be listed anymore.
If there are other things you’re trying to figure out, I highly suggest GitLab’s README. It’s a great starting point and as tons of answers.
I hope this tutorial helped you get GitLab up and running with Apache. If you have any questions or issues, leave a comment and I’ll reply when I can.
Before running ‘gitlab-ctl reconfigure’, first run ‘gitlab-ctl start postgresql’, else there will be an error that postgresql is not running.
Pingback: Instalación y configuración Gitlab y Apache | Hunabsys Blog
Also make sure the directory has permissions:
Require all granted
Otherwise this will results in bunch of 403s
Pingback: [ASK] server - Remove double slash in gitlab address | Some Piece of Information
I get this error:
I do have a user and group apache, and apache runs as apache. Any ideas?
You have to make sure there are no services running under user
apache
before running the reconfigure part of this tutorial, otherwise it will fail. I had bothapache
running andphp-fpm
. Find what processes are running using this command:Then stop any service running, run reconfigure, and start the services again:
Now I’m having trouble with getting a 503 service unavailable when trying to access my Git URL.
I’m having the same problem, were you able to solve it?
Pingback: Installing Gitlab | baligena.com
I got this to work on Ubunto 16-LTS by additionally following the instructions at https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/nginx.md#using-a-non-bundled-web-server and using the .conf file found at https://gitlab.com/gitlab-org/gitlab-recipes/blob/master/web-server/apache/gitlab-apache24.conf, and manually enabling the mods listed on this latter file.
Moving from Nginx to Apache also solved the problem of not being able to use static files such as users’ avatars, by the way.
Pingback: Install Gitlab on Apache in Ubuntu | JMJTwin Blog
By default, Nginx is configured to start automatically at server startup. If you do not want so so, you can disable the configuration with using:
$ Sudo systemctl disable nginx
To enable this service to boot your computer at startup, you can type:
$ Sudo systemctl allows nginx
Thank you Bro it’s work properly.
but how can i set this up to work with HTTPS ?
any idea ?
Have you tried listening on port 443 in the Apache config?
Hi, the gitlab css doesn’t load is there a way to fix this
I’ve followed every step, and even had to do a lot of messing around in order to get this right (multiple vhosts on the server), but I’m getting a 403 Forbidden.
I’ve tried using Directory and Require all granted, but that just gives me “Index of”.
Any idea?
solution for css not loading :
https://forum.gitlab.com/t/no-css-gitlab-not-working/21249/2
Pingback: Trying to install GitLab on Apache on CentOS 7 - Boot Panic