When you configure external_url 'https://mydomain.com' in your gitlab.rb file and enable Let's Encrypt, GitLab automates the process to obtain a free SSL certificate for mydomain.com. However, this setup does not automatically cover the www subdomain (https://www.mydomain.com) unless explicitly configured to do so. SSL certificates are issued to the exact domain name specified, and mydomain.com and www.mydomain.com are considered different entities in the context of SSL certificates.
To cover both the root domain (mydomain.com) and the www subdomain (www.mydomain.com), you have a couple of options:
1. Obtain a Certificate with Subject Alternative Names (SAN)
When setting up Let's Encrypt for GitLab, you can manually obtain a certificate that includes both mydomain.com and www.mydomain.com as Subject Alternative Names (SAN). To do this, you might need to use the Let's Encrypt certbot tool or another ACME client manually, as the GitLab automated Let's Encrypt integration typically targets the single domain specified in the external_url.
After obtaining the certificate with both domains listed as SAN, you can configure GitLab to use the custom certificate instead of the automatic Let's Encrypt process:
- Disable the built-in Let's Encrypt support in
gitlab.rb by setting letsencrypt['enable'] = false.
- Provide paths to your manually obtained certificate and private key using the
nginx['ssl_certificate'] and nginx['ssl_certificate_key'] settings in gitlab.rb.
2. Redirect www to the non-www domain (or vice versa)
If your primary goal is to ensure visitors can access your GitLab instance regardless of whether they type www or not, you can set up a redirection from www.mydomain.com to mydomain.com, or the other way around, depending on which domain your SSL certificate covers.
This approach requires you to:
- Configure DNS: Make sure the DNS records for both
mydomain.com and www.mydomain.com point to your GitLab server.
- Configure Redirection: The redirection can be configured at the DNS provider level (if supported), at the web server level (e.g., Nginx or Apache configuration outside of GitLab), or via GitLab's built-in Nginx by customizing the nginx configuration template files.
The redirection option is simpler and does not require you to manually manage SSL certificates, but it means that one form of the domain URL (either with or without www) will always redirect to the other, and only one form will be used for GitLab access.
Note: Always remember to reconfigure GitLab (sudo gitlab-ctl reconfigure) and reload/restart the GitLab Nginx server after making changes to gitlab.rb or the Nginx configuration.
In summary, to cover both mydomain.com and www.mydomain.com with SSL certificates from Let's Encrypt, you would likely need to manually manage the certificates or decide on a primary domain and redirect from the other. The GitLab automated Let's Encrypt feature simplifies the process for single domains but may not directly support multiple subdomains or SAN configurations without some additional manual setup.