Setting up Gitlab Pages

Setting up Gitlab Pages

I started a while back with setting up Gitlab Pages for replacing my personal website and setting up some doc pages. Setting everything up and getting this website to work, especially on custom domain names, was quite the adventure.


Since I’ve previously pointed the DNS for and * to the gitlab server, I could simply enable pages to work on a subdomain of that. In My case


The config was basically nothing more than adding/editing /etc/gitlab/gitlab.rb and adding

pages_external_url ''

And updating Gitlab via gitlab-ctl reconfigure.

I’ve created this site project from template and pushed it to Gitlab with devops enabled. Somehow the first pipeline failed due to some ssl bitching. I updated the theme, by replacing it with a git submodule but the pipeline started bitching the following:

Cloning into '/builds/pat.vdleer/website/themes/beautifulhugo'...
fatal: unable to access '': SSL certificate problem: unable to get local issuer certificate
fatal: clone of '' into submodule path '/builds/pat.vdleer/website/themes/beautifulhugo' failed

I was not in the mood so I “fixed” it quick and dirty by replacing the submodule with the actual files and committing that. One of those things for on the (never-gonna) todo-list.

The site was now up and running on, not a very pretty url so the next thing to do was custom DNS names

Custom domains

I dove in and figured out I needed a second IP to run the pages on since you (currently) can’t run pages and gitlab on a single IP. As far as I can tell, Pages doesn’t use nginx when you want to run it with custom domains. Since it doesn’t support using nginx as a catch all reverse proxy and pipe it to pages I figured I would go for the easier solution, a second IP.

IP config

I added (bought) a second one and added it to my VPS but didn’t know how to configure this. I figured it would add a second interface and I would have to bring it up. Checking my uptime, 1065 days, I couldn’t bring myself to rebooting and trying it out so I asked a friend to help out.

He configured it as an IP alias in /etc/network/interfaces.

source /etc/network/interfaces.d/*

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto ens3
iface ens3 inet dhcp
# This is an autoconfigured IPv6 interface
iface ens3 inet6 auto

# The secondary network interface (aliased)
auto ens3:0
iface ens3:0 inet static
# gateway

After restarting networking via /etc/init.d/networking restart it worked!

Gitlab config

So back to /etc/gitlab/gitlab.rb and configure the pages.

external_url ''
registry_external_url ""
pages_external_url ''

nginx['listen_addresses'] = ['']

pages_nginx['enable'] = false
gitlab_pages['access_control'] = true
gitlab_pages['enable'] = true
gitlab_pages['external_http'] = ['']
gitlab_pages['external_https'] = ['']
# gitlab_pages['redirect_http'] = true
# gitlab_pages['use_http2'] = true
# gitlab_pages['inplace_chroot'] = true

It took quite some time but this is basically what I landed on.

Running gitlab-ctl reconfigure, everything was up, or so it seemed.

Pages was now redirecting to registry, which redirected to gitlab itself…

After some googling I found a bug report about the registry not listening to nginx['listen_addresses'] = ['']. Adding registry_nginx['listen_addresses'] = [''] should fix this.

But… still the same… so after a lot of screwing around I nmaped the IP of pages and found out that the 80 and 443 were closed.

At this time I started looking at the pages log Using gitlab-ctl tail gitlab-pages it showed me the following;

  "error":"open /etc/gitlab/ssl/ no such file or directory",

Apparently the service wasn’t starting due to a missing ssl certificate.

SSL config

So running certbot to the resque in providing me with a cert. Running certbot I came across another issue, you can’t bind certbot to a specific IP, it binds on and since gitlab is running it can’t do that.

$ certbot certonly --standalone --preferred-challenges http -d
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for
Cleaning up challenges
Problem binding to port 80: Could not bind to IPv4 or IPv6.

Stopping gitlab fixed this issue, but still a bit strange that there isn’t an option for this.

So once that was fixed I simply symlinked the cert and check the logs.

ln -s /etc/letsencrypt/live/ /etc/gitlab/ssl/

I knew there should be a key file put somewhere so I checked the logs, found the name and fixed that as well.

  "error":"open /etc/gitlab/ssl/ no such file or directory",
ln -s /etc/letsencrypt/live/ /etc/gitlab/ssl/

But… it still kept redirecting… this was seriously driving me mad…

It took me way way too long but eventually I noticed it. Remember in the beginning when I set up the DNS to gitlab? Well… since I switched IP’s I forgot to update the pages entry to my new second IP.

Since it takes a while to update the DNS I tested it with curl.

$ curl -v --resolve ''
* Added to DNS cache
* Rebuilt URL to:
* Hostname was found in DNS cache
*   Trying
* Connected to ( port 80 (#0)
> GET / HTTP/1.1
> Host:
> User-Agent: curl/7.58.0
> Accept: */*
< HTTP/1.1 302 Found
< Content-Type: text/html; charset=utf-8
< Location:

FINALLY, or so I thought, this too redirect me to projects.pages which in its turn redirect me gitlab itself back again… Checking my custom domain for this project/website/pages gave me the following.

$ curl -v --resolve ''
* Added to DNS cache
*   Trying
* Connected to ( port 80 (#0)
> GET /website HTTP/1.1
> Host:
> User-Agent: curl/7.58.0
> Accept: */*
< HTTP/1.1 301 Moved Permanently
< Server: nginx
< Date: Wed, 10 Jul 2019 22:03:19 GMT
< Content-Type: text/html
< Content-Length: 178
< Connection: keep-alive
< Location:

In the morning I tried again and my DNS name, just worked but as soon as I pushed a new blog post, the beginning of this one, trouble hit again. The runners were not running so the project could not go through the pipeline. Checking the config everything seemed fine so I opted for adding a new one which did fail…

ERROR: Registering runner... failed                 runner=CuftyRsQ status=couldn't execute POST against Post dial tcp getsockopt: connection refused
PANIC: Failed to register this runner. Perhaps you are having network problems

Since nginx wasn’t running on anymore the binding was not set on the loopback. Luckily this was quickly fixed by checking /etc/hosts which gave me:       localhost gitlab

Removing the from the file fixed it, but now I wonder why I added that… I don’t think it was done automagically, something in the back of my mind tells me it has something todo with mail but that seems to work…

For now I’m just happy it finally all works.

See also