DEV Community

Cover image for Setup Jenkins and Gitlab on Custom Subdomain with Nginx Proxy Manager
Nosa Shandy
Nosa Shandy

Posted on

Setup Jenkins and Gitlab on Custom Subdomain with Nginx Proxy Manager

📍 Description

The goal on this tutorial to make the small labs that the Jenkins, and Gitlab can run on the VPS and also we can access them with custom subdomain like:

  • jenkins.domain.com
  • gitlab.domain.com

Nginx Proxy Manager

To make this possible, we need help Nginx Proxy Manager to create proxy to our specific IP Address and port. We will install the jenkins, and gitlab on the docker to make the installation easy.

📍 Getting Started

To get started, we need follow this step by step:

  1. Install Docker
  2. Install Nginx Proxy Manager on Docker
  3. Install Jenkins & Gitlab on Docker
  4. Add the DNS Manager and set A record subdomain to VPS IP

At this post, I using the Ubuntu 22, the installation it's depend on the server you using, but on the main line, it's the same.

🔥 Install the docker & docker-compose

First, we install docker with this command:

apt install docker

And, we install docker-compose

apt install docker-compose

The docker needed to further action like install the Nginx Proxy Manager, Jenkins and Gitlab. So, make sure you install the docker before do another thing.

🔥 Install Nginx Proxy Manager on Docker

Docker, check! Next, we install the Nginx Proxy Manager on Docker by using this step by step.

  • Create a new directory and add docker-compose.yml file similar to this on your new directory:
version: '3'
services:
  app:
    image: 'jc21/nginx-proxy-manager:latest'
    restart: unless-stopped
    ports:
      - '80:80'
      - '81:81'
      - '443:443'
    volumes:
      - ./data:/data
      - ./letsencrypt:/etc/letsencrypt
Enter fullscreen mode Exit fullscreen mode
  • Bring up your stack by running
docker-compose up -d
Enter fullscreen mode Exit fullscreen mode
  • Log in to the Admin UI using this default password:
http://your-vps-ip:81
Email:    admin@example.com
Password: changeme
Enter fullscreen mode Exit fullscreen mode

All this step by step is same on the original nginx proxy manager documentation:
https://nginxproxymanager.com/guide/#quick-setup

🔥 Install Jenkins

Okay, nginx proxy manager is already installed, next we need install jenkins on docker.

You can run this command to install the jenkins on your vps:

docker run -d --name jenkins -p 9091:8080 -p 50000:50000 jenkins/jenkins:lts-jdk11
Enter fullscreen mode Exit fullscreen mode

After that, your Jenkins will be run on port 8080, you can grep the initial password on the docker logs.

Navigate to http://your-vps-ip:9091 and setup the Jenkins with the initial password.

🔥 Install Gitlab

We successfully install the jenkins and looks like jenkins work perfectly fine, next we need to install gitlab on docker!

  • Run this command for initial before install gitlab
mkdir -p gitlab; cd gitlab/
mkdir -p /srv/gitlab/{config/ssl,logs,data}
Enter fullscreen mode Exit fullscreen mode
  • Define the environment variable "GITLAB_HOME" with the value as GitLab data directory "/srv/gitlab" as below.
GITLAB_HOME=/srv/gitlab
Enter fullscreen mode Exit fullscreen mode
  • Go to gitlab directory and add docker-compose.yml file similar to this on gitlab directory, edit the domain and hostname:
web:
  image: 'gitlab/gitlab-ce:latest'
  restart: always
  hostname: 'gitlab.yourdomain.com'

  environment:
    GITLAB_OMNIBUS_CONFIG: |
      # Add any other gitlab.rb configuration here, each on its own line
      external_url 'http://gitlab.yourdomain.com'
      gitlab_rails['gitlab_shell_ssh_port'] = 2224

  ports:
    - '8081:80'
    - '4443:443'
    - '2224:22'

  volumes:
    - '${GITLAB_HOME}/config:/etc/gitlab'
    - '${GITLAB_HOME}/logs:/var/log/gitlab'
    - '${GITLAB_HOME}/data:/var/opt/gitlab'
    - '${GITLAB_HOME}/config/ssl:/etc/gitlab/ssl'
Enter fullscreen mode Exit fullscreen mode
  • Run the installation
docker-compose up -d
Enter fullscreen mode Exit fullscreen mode
  • Get the gitlab initial root password by using this command
sudo docker exec -it gitlab grep 'Password:' /etc/gitlab/initial_root_password
Enter fullscreen mode Exit fullscreen mode

📍 Add the DNS Manager and set A record subdomain to VPS IP

All the application is already installed. Yey! Next, we need to pointing our custom subdomain to our VPS / Nginx Proxy Manager, and we will manage the subdomain on our Nginx Proxy Manager.

  • Go to your domain DNS Management, and add the subdomain jenkins, gitlab and pointing to your vps (that we install nginx proxy manager, jenkins, gitlab) like screenshot below.

DNS Management

  • Go to Nginx Proxy Manager, add the subdomain that we already setup earlier and add the your vps IP and Port.

Example: We setup the jenkins on port 9091, so we input the your-vps-ip:9091 on the Forward Hostname / IP sections, as shown on the screenshot below.

Jenkins

  • Add the SSL

Go to SSL tab on the right side and set the SSL as shown on the screenshot below.

Jenkins Nginx Proxy Manager

And saved the changes.

  • Go to your subdomain!

After that, you just need to navigate to your jenkins subdomain, and you will see the jenkins webservice on your subdomain.

Jenkins Nginx Proxy Manager

Great! Mission Success! Now, you can add the gitlab and proxy manager custom subdomain too!

🔥 References:

https://forum.gitlab.com/t/how-to-login-for-the-first-time-local-install-with-docker-image/55297
https://www.howtoforge.com/how-to-install-gitlab-with-docker-on-ubuntu-2004/
https://octopus.com/blog/jenkins-docker-install-guide
https://nginxproxymanager.com/guide/#quick-setup
https://aksarakode.com/

Top comments (2)

Collapse
 
szabgab profile image
Gabor Szabo

Nice first post. You might want to add #gitlab as a tag

Collapse
 
nosashandy profile image
Nosa Shandy

Sorry, missclick to publish the article when the article on halfway. Thanks for the suggestion, I already add #gitlab as well.