Omnibus GitLab and additional Nginx virtual hosts

So you have a beast of a machine running GitLab and your like, "Man I feel like this thing could probably host some static websites too". Well, you're in luck. The following procedures will have you running additional virtual hosts with the nginx server that is installed with the omnibus version of GitLab.

Environment:

OS: Ubuntu 16.04.4 LTS

Gitlab: Latest [11.4.0] at time of writing

Nginx: Installed via Omnibus with GitLab

Nginx Configuration

Create the default nginx file structure

mkdir -p /etc/nginx/sites-available  
mkdir -p /etc/nginx/sites-enabled  

Make sure you create the file structure specified in the nginx config

mkdir -p /var/www/example.com/html  

Create a sample virtualhost config for nginx

vi /etc/nginx/sites-available/example.com.conf  

Virtualhost config contents

server {  
        listen 80;
        listen [::]:80;

        root /var/www/example.com/html;
        index index.html index.htm index.nginx-debian.html;

        server_name example.com;

        location / {
                try_files $uri $uri/ =404;
        }
}

Enable the test config by creating a symlink to the new config in the sites-enabled directory

ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/  

GitLab Configuration

Modify the gitlab.rb file to make it include All of the config files in the sites-enabled directory.

vi /etc/gitlab/gitlab.rb  

Uncomment the custom_nginx_config line and tune it as follows. The trailing semicolon in the line is required

nginx['custom_nginx_config'] = "include /etc/nginx/sites-enabled/*.conf;"  

Restart and Reconfigure GitLab

gitlab-ctl recompile  

Result

By adding a line to your hosts file you should now be able to access your newly created virtualhost.

vi /etc/hosts  
192.168.1.13 example.com #change the ip to whatever the address is of your gitlab server  

Troubleshooting

If for some reason the nginx server does not come back up, you can tail all the services to find out what the problem is with the following command.

gitlab-ctl tail