MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

GitLab Tutorials: Using letsencrypt with Gitlab self hosted server

A self-managed GitLab server installed with the Linux (Omnibus) package can get and renew free TLS certificates from Let's Encrypt by itself. You point a public DNS record at the server, set an https:// external URL and the Let's Encrypt options in /etc/gitlab/gitlab.rb, then run gitlab-ctl reconfigure. This page adds the exact configuration, the prerequisites, how to check and renew the certificate, and fixes for the most common errors.

Step 1 – Create a valid DNS entry

Step 2 – Do following changes

Terminal grep of gitlab.rb showing letsencrypt enable true and contact_emails set
Terminal grep of gitlab.rb showing external_url set to https://gitlab.devopsschool.com

Step 3 – Run following commands

$ sudo gitlab-ctl reconfigure

How the built-in Let's Encrypt integration works

The GitLab Linux package bundles an ACME client that runs during gitlab-ctl reconfigure. It requests a certificate for the hostname in external_url and proves you control that hostname with the HTTP-01 challenge. Let's Encrypt connects to http://<your-host>/.well-known/acme-challenge/... on port 80, and GitLab's bundled NGINX serves the token.

When validation succeeds, the certificate and key are written to /etc/gitlab/ssl/<hostname>.crt and /etc/gitlab/ssl/<hostname>.key, and NGINX is reconfigured to serve HTTPS. Let's Encrypt certificates are valid for 90 days, so GitLab also sets up a scheduled renewal job.

Note: If external_url starts with https:// and no certificate files already exist in /etc/gitlab/ssl, the package turns Let's Encrypt on automatically. If certificates from an earlier manual setup are present, you must set letsencrypt['enable'] = true explicitly.

Prerequisites

  • GitLab installed with the official Linux package (Omnibus) or the official Docker image. Source installations and Helm chart deployments use different methods.
  • A fully qualified domain name, for example gitlab.example.com, with a public DNS A record (and an AAAA record if you use IPv6) pointing to the server's public IP address.
  • Inbound TCP port 80 and port 443 open from the internet, in the host firewall and in any cloud security group. Port 80 is required for validation even if you only plan to serve HTTPS.
  • A working email address for expiry and account notices from Let's Encrypt.

Check DNS and the firewall before you change GitLab. Run the first command from a machine outside your network:

# The answer must be the server's public IP address
dig +short gitlab.example.com

# Ubuntu with ufw
sudo ufw allow http
sudo ufw allow https
sudo ufw status

# RHEL / Rocky / Alma with firewalld
sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reloadCode language: PHP (php)

Configure gitlab.rb

The screenshots in Step 2 above show the edits to /etc/gitlab/gitlab.rb. Here they are as text you can copy. Open the file with sudo vi /etc/gitlab/gitlab.rb (or another editor), then set or uncomment these lines:

## Must use https and the exact DNS name from Step 1
external_url 'https://gitlab.example.com'

## Let's Encrypt integration
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['admin@example.com']

## Automatic renewal (runs as a cron job)
letsencrypt['auto_renew'] = true
letsencrypt['auto_renew_hour'] = 0
letsencrypt['auto_renew_minute'] = 30
letsencrypt['auto_renew_day_of_month'] = "*/4"

## Send plain HTTP traffic to HTTPS
nginx['redirect_http_to_https'] = trueCode language: PHP (php)
  • external_url sets the hostname on the certificate. The https:// scheme is what makes GitLab listen on 443 and request a certificate.
  • letsencrypt['contact_emails'] is the address registered with your Let's Encrypt account.
  • The auto_renew_* settings make GitLab try a renewal at 00:30 every fourth day. A certificate is only replaced when it is close to expiry, so frequent checks are safe.
  • nginx['redirect_http_to_https'] keeps port 80 open for the ACME challenge and redirects all other requests to HTTPS.

If you also serve the container registry on its own hostname, give it an https URL as well, for example registry_external_url 'https://registry.example.com'. That hostname also needs a DNS record that points to this server.

Apply the change and verify the certificate

  1. Run sudo gitlab-ctl reconfigure as shown in Step 3 above. Watch for the letsencrypt and acme_certificate resources in the output. The run fails with an error if validation fails.
  2. Confirm the certificate files exist: sudo ls -l /etc/gitlab/ssl/.
  3. Check the issuer and validity dates from another machine with the openssl command below.
  4. Open https://gitlab.example.com in a browser. You should see a valid padlock without a warning.
echo | openssl s_client -connect gitlab.example.com:443 -servername gitlab.example.com 2>/dev/null \
  | openssl x509 -noout -subject -issuer -dates

# Expected output (values will differ):
# subject=CN = gitlab.example.com
# issuer=C = US, O = Let's Encrypt, CN = ...
# notBefore=...
# notAfter=...   (about 90 days later)Code language: PHP (php)

Note: After you switch to HTTPS, update existing Git remotes, webhooks and runner registrations that still use the http:// URL. Redirects do not always work for API clients or git push.

Renewal

With auto_renew enabled, GitLab adds a root cron entry that renews the certificate. You can view it and trigger a renewal yourself:

# Show the renewal cron entry created by GitLab
sudo crontab -l

# Renew now (only replaces the certificate if it is due)
sudo gitlab-ctl renew-le-certsCode language: PHP (php)

Renewal uses the same HTTP-01 challenge. If you close port 80 or change DNS after the first certificate is issued, renewal will fail silently until the certificate expires. Check the expiry date as part of your regular monitoring.

Common errors and fixes

SymptomLikely causeFix
Reconfigure fails with a connection refused or timeout during validationPort 80 is blocked by the host firewall, a cloud security group or the ISPOpen TCP 80 to the internet and run sudo gitlab-ctl reconfigure again
Validation error mentioning DNS or NXDOMAINThe DNS record does not exist yet or has not propagatedCreate the A record, wait until dig +short returns the public IP, then retry
Validation returns 404 or reaches the wrong serverDNS points to a different IP, or a load balancer or proxy in front of GitLab does not forward /.well-known/acme-challenge/Fix the record, or terminate TLS on the proxy and disable GitLab's Let's Encrypt
Let's Encrypt is never requestedOld certificate files are already in /etc/gitlab/ssl, or external_url still uses http://Set letsencrypt['enable'] = true, move the old files out of the way and check external_url
Error about too many certificates or failed authorizationsLet's Encrypt rate limits were hit after repeated failed attemptsFix the root cause first, then wait for the rate-limit window to reset before retrying
Browser still shows the old or self-signed certificateNGINX did not reload, or the browser cached the old certificateRun sudo gitlab-ctl restart nginx and test again with openssl s_client

Internal servers, proxies and Docker

  • Server not reachable from the internet: HTTP-01 validation cannot work. Get a certificate with the DNS-01 challenge using an external ACME client such as certbot with a DNS plugin, or use a certificate from an internal CA. Then set letsencrypt['enable'] = false and point nginx['ssl_certificate'] and nginx['ssl_certificate_key'] at the files.
  • Behind a load balancer or reverse proxy that terminates TLS: handle certificates on the proxy. Set letsencrypt['enable'] = false, nginx['listen_https'] = false and nginx['listen_port'] = 80 so GitLab serves plain HTTP behind the proxy.
  • Docker: put the same settings in the GITLAB_OMNIBUS_CONFIG environment variable or in the mounted /etc/gitlab/gitlab.rb. Publish ports 80 and 443 on the host and mount /etc/gitlab as a persistent volume so the certificates survive container restarts.
docker run -d --name gitlab --hostname gitlab.example.com \
  -p 80:80 -p 443:443 -p 2222:22 \
  -e GITLAB_OMNIBUS_CONFIG="external_url 'https://gitlab.example.com'; letsencrypt['enable'] = true; letsencrypt['contact_emails'] = ['admin@example.com']" \
  -v /srv/gitlab/config:/etc/gitlab \
  -v /srv/gitlab/logs:/var/log/gitlab \
  -v /srv/gitlab/data:/var/opt/gitlab \
  gitlab/gitlab-ee:latestCode language: JavaScript (javascript)

Corrections and missing steps in the original

  • Step 1 does not say which record to create. It must be a public A (or AAAA) record whose name exactly matches the hostname in external_url.
  • Step 2 shows the configuration only as screenshots, which cannot be copied and may differ between versions. The text version is in the configure section above.
  • The original leaves out the port 80 requirement. It is the most common reason the first gitlab-ctl reconfigure fails.
  • The original has no verification or renewal steps. Without them a failed renewal goes unnoticed until the certificate expires after 90 days.

Frequently asked questions

Does GitLab renew Let's Encrypt certificates automatically?

Yes, when letsencrypt['auto_renew'] = true is set. GitLab creates a cron job that runs gitlab-ctl renew-le-certs on the schedule you configure. Port 80 must stay reachable from the internet for renewal to succeed.

Can I use Let's Encrypt with a GitLab server on a private network?

Not with the built-in integration, because it uses the HTTP-01 challenge, which needs Let's Encrypt to reach your server on port 80. Get the certificate with a DNS-01 client such as certbot with a DNS plugin, then configure it in GitLab as a manual certificate.

Where does GitLab store the Let's Encrypt certificate?

In /etc/gitlab/ssl/, named after the hostname, for example gitlab.example.com.crt and gitlab.example.com.key. Include /etc/gitlab in your backups, because the standard GitLab backup does not cover it.

Why does gitlab-ctl reconfigure fail at the acme_certificate step?

Usually DNS does not yet point to the server, or port 80 is blocked by a firewall or security group. Check both from outside your network, fix the problem and run reconfigure again. Avoid retrying many times in a row, or you may hit Let's Encrypt rate limits.

Can I get a wildcard certificate with GitLab's built-in Let's Encrypt support?

No. Wildcard certificates require the DNS-01 challenge, which the built-in integration does not perform. Get a wildcard certificate with an external ACME client and configure it manually.

Related tutorials

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals

Related Posts

The Ultimate Guide to Uptime, Health, Synthetic and Infrastructure Monitoring: A Complete Taxonomy

Instead of categorizing by vendor or product, we should categorize by what is monitored, how it is monitored, and what failures can be detected. For example, UptimeRobot,…

Read More

How to generate Letsencrypt certificates with Verifying domain using API

acme.sh can get a Let's Encrypt certificate by proving you control a domain through your DNS provider's API. It creates a temporary TXT record, so you never…

Read More

Openshift: How to configure Azure openshift ARO with Custom Domain

Step-by-Step Guide: Configuring Azure Red Hat OpenShift (ARO) with a Custom Domain Setting up a custom domain for your ARO cluster involves both Azure and DNS provider…

Read More

Top 51 free open source tools for system network, DNS, HTTP, SSL & Security for software engineers

Network   ๐Ÿ”ธ PuTTY – is an SSH and telnet client, developed originally by Simon Tatham.  ๐Ÿ”ธ Mosh – is a SSH wrapper designed to keep a SSH session alive over a volatile…

Read More

How to Installing Rancher on a Single Node Using Docker

This guide covers installing Rancher on a single Linux host with one docker run command. It walks through all four TLS options: Rancher's built-in self-signed certificate, your…

Read More

Cert Manager: Generate TLS Certificates Using Self Signed Issuers

This page shows how to use cert-manager to create a private certificate authority (CA) from a self-signed issuer, then use that CA to issue TLS certificates for…

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x