User Tools

Site Tools


gitlab_nginx_additional

Gitlab NGINX custom/additional config

Sometimes it's handy to have a additional domain configured for the Gitlab Omnibus bundled NGINX Server. Even though it is not encouraged doing so by Gitlab, it is still possible.

Gitlab config

Edit /etc/gitlab/gitlab.rb and add/change the following values

gitlab.rb
# Includes all *.conf files in this folder, requires gitlab-ctl reconfigure
nginx['custom_nginx_config'] = "include /etc/nginx-gitlab/sites/*.conf;"
 
# Letsencrypt is required to make SSL work with this setup
letsencrypt['enable'] = true
 
# Alternative names - add each domain/subdomain you want to
# include in the SSL certificate to the "alt_name" array.
# Does not support wildcard domains!
letsencrypt['alt_names'] = ['example.com', 'www.example.com']

Additional NGINX config

Create folder /etc/nginx-gitlab/sites and add the following file:

example.com.conf
server {
        listen 80 default_server;
        listen [::]:80 default_server;
 
        root /path/to/doc/root;
        index index.html index.htm;
 
        server_name example.com www.example.com;
 
        location / {
                try_files $uri $uri/ =404;
        }
 
	location /.well-known/acme-challenge/ {
		 root /var/opt/gitlab/nginx/www/;
	}
}
 
server {
        listen 443 ssl;
        listen [::]:443 ssl;
 
        root /path/to/doc/root;
        index index.html index.htm;
 
        server_name example.com www.example.com;
 
        # Refer to Gitlabs letsencrypt cert here.
        ssl_certificate /etc/gitlab/ssl/gitlab.example.com.crt;
        ssl_certificate_key /etc/gitlab/ssl/gitlab.example.com.key;
        ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers         HIGH:!aNULL:!MD5;
 
 
        location / {
                try_files $uri $uri/ =404;
        }
 
        location /.well-known/acme-challenge/ { 
                 root /var/opt/gitlab/nginx/www/; 
        }
}

Run gitlab-ctl reconfigure to apply the changes made to the configuration.

gitlab_nginx_additional.txt · Last modified: 2021/12/06 22:15 by admin