Installing Gitlab under Reverse Proxy of aaPanel

How to install Gitlab under Reverse Proxy of any existing webserver? We will be installing Gitlab in an Amazon Web Server Elastic Compute server - AWS EC2 - t2.medium version. You can use any VM or container environment with minimum 2 cpu cores and 4 GB of RAM.

We will be using an Ubuntu server os for the above. Please update OS using commands below:

sudo apt-update
sudo apt-upgrade

Install the dependencies before installing Gitlab:

sudo apt-get install -y curl openssh-server ca-certificates tzdata perl

For Gitlab EE, you can refer to the following link: https://about.gitlab.com/install/#ubuntu. It just has different installation Curl URL. We will be using Gitlab-CE for installation using a different CURL URL. The rest of the process will be same for any Gitlab installation.

Get package of Gitlab CE - community edition from the link below by using the curl command therein. https://packages.gitlab.com/gitlab/gitlab-ce/install

curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

Install Gitlab using the command below:

sudo apt-get install gitlab-ce

After completion of installation, edit the gitlab configuration file below:

sudo nano /etc/gitlab/gitlab.rb

Uncomment and change the following entries to your own domain name and the localhost port that you would like to use (Be sure to allow the port in your firewall).

external_url 'https://yourgitlab.example.com'
gitlab_rails['trusted_proxies'] = ['127.0.0.1']
nginx['listen_port'] = 9000
nginx['listen_https'] = false

Update the Gitlab configuration by running the command:

sudo gitlab-ctl reconfigure

Create the website domain in aaPanel and update the Reverse Proxy menu. Click Add for adding new reverse proxy.

Target URL: http://127.0.0.1:9000/
Sent Domain: $http_host

Click on conf for manual editing. Check of the following values and update any if required.

proxy_pass http://127.0.0.1:9000/;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_http_version 1.1;

Congratulations! Now your Gitlab web app is accessible in your require domain/subdomain using reverse proxy in the same web server where you can host other websites as well.