This post is about setting up Gitlab with the shipped nginx on a shared server behind apache with multiple other web services running on it. That is NOT a recommended setup and you should use a dedicated VPS and nginx only to prevent problems. I only configured like this because the server I used was already running something else with apache on port 80.

Last year I had to setup a git server for my team. Prior to that moment, I had only used Github and my mates were only familiar with SVN. I chose gitolite to control access to the git server on a Linode VPS. It took me quite a few days before I finally successfully got gitolite up and running.

However, the workflow of gitolite was definitely not very pleasant. To add new member, set permission or make other configurations, I had to add public keys and change files in a gitolite-admin repository and push to my server. My days were like this:

- Add new member – edit and push, 
- Add new repo – edit and push, 
- Give permission – edit and push
- etc.

Eventually, I figured out how to let the user create repositories by themselves. However, I still had to help them set permissions for other users. May be there are some other ways to make my life easier with gitolite, but it’s still a pain in the ass. After I handed the process to another person, I never looked back again. Until this morning.

Yesterday morning I decided that enough is enough, I gave Gitlab a try. I spun up a brand new VPS and installed it. I did have a look at Gitlab a while a go, but at that time the installation was pretty complicated to me, I didn’t have a new server and if I accidentally messed up, my life, and my teammates lives, would be ruined.


Gitlab has 3 versions: Gitlab CE – the free version, Gitlab CC has enterprise features (can’t understand the list, seriously) and Gitlab.com – similar to Bitbucket. The installation is pretty straight forward, available on the download page. At least until the process is finished and you cannot connect to the front end.


First, since I have already had something running on the VPS at port 80, Gitlab cannot use the port. Instead, I had to give Gitlab another port, and another domain for convenience. So I opened /etc/gitlab/gitlab.rb and changed external_url property to match my domain:

external_url 'http://my.domain'

Then, I headed to /opt/gitlab/embedded/conf/nginx.conf to changed the port and server name as follow:

server {
    listen [MY DESIRED PORT];
    server_name 127.0.0.1;
    ...
}

Since my server is currently using apache2, I also had to add to the configuration at /etc/apache2/ports.conf the following settings:

<VirtualHost *:80>
    ProxyPreserveHost On
    ServerName git.mininoic.com
    ProxyPass / http://localhost:[MY DESIRED PORT]/
    ProxyPassReverse / http://localhost:[MY DESIRED PORT]/
</VirtualHost>

Seem easy enough. However, at this point, if you attempt to restart apache, you will only get an error page. I didn’t note down or take a screenshot, so you might have to figure it out on your own if you want, but the problem was just that I didn’t include some mod files. Just run the follow commands and everything will be fine.

a2enmod proxy
a2enmod proxy_http
service apache2 restart

Then, as I was able to connect to my front end, I received a beautiful 500-error page of Gitlab, told me that something was wrong, without any useful information whatsoever.

Something is not right? What did I miss?

I didn’t know what to do, so I googled around, until I realized there is a log file. Dumb me! The log file can be accessed by using:

sudo gitlab-ctl tail

I noticed the following part:

FATAL:  could not create shared memory segment: Invalid argument
...
HINT:  This error usually means that PostgreSQL's request for a shared memory segment exceeded your kernel's SHMMAX parameter.  You can either reduce the request size or reconfigure the kernel with larger SHMMAX. To reduce the request size ... reduce PostgreSQL's shared memory usage, perhaps by reducing shared_buffers or max_connections.

According to Google [dah] and the error specified, the fix was pretty simple: in the gitlab.rb file, change the following settings:

postgresql['shared_buffers'] = "1MB"
postgresql['shmmax'] = 4294967295
postgresql['shmall'] = 1048575

After messing around with the root user, I decided to create my own account. Gitlab gloriously told me that it had successfully created my account and kindly asked me to check for an activation email. I checked my inbox, I checked my spam mails. But there wasn’t any email to be found.

I tried to restart and reconfigured Gitlab so many times, even tried to use Gmail with SMTP instead of the built in solution. I never did successfully authorized Gitlab with Gmail nor figured out what went wrong. At the end of the morning, I removed all my changes. Guess what? The mail is working now. No idea why???

Anyway, now my team is settling down with Gitlab, and I hope nothing bad is coming :(

Loading comments

netcell

Software engineer with 4+ years of work experience in designing and developing cross-platform games and apps on web technology.