Set up Jenkins on Ubuntu 18.04 with LetsEncrypt (HTTPS) using Nginx
There are a number of articles out there on how to set up Jenkins on Ubuntu, but I ran into a couple of problems while trying to set the whole system up so I’ve decided to write down steps I followed to get this all sorted. It was basically a mixture of:
- https://linuxconfig.org/install-jenkins-on-ubuntu-18-04-bionic-beaver-linux
- https://wiki.jenkins.io/display/JENKINS/Installing+Jenkins+on+Ubuntu
- https://websiteforstudents.com/install-jenkins-on-ubuntu-16-04-17-10-18-04-lts-server/
- https://wiki.jenkins.io/display/JENKINS/Jenkins+says+my+reverse+proxy+setup+is+broken
And a couple of other Google results :P
Just to add a bit of context before I jump in, I’m using a KVM virtual machine and setting this system up from a clean Ubuntu 18.04 installation. For this article, let’s assume I’ve set up the DNS entries to point jenkins.example.com to my public IP for this virtual machine.
So let’s jump in! First, we need to install Java,
Keep in mind that I’m using Ubuntu 18 which is why you don’t have to run apt-get update above.
Once that’s installed, it’s time to install Jenkins,
Next we need to install Nginx and Certbot so that we can put the Jenkins behind an https connection,
Now we need to set up the Nginx config to act as a proxy to Jenkins which is running on http://localhost:8080. Use your favourite editor to open and edit /etc/nginx/sites-available/default and make the file look as follows,
Make sure you change jenkins.example.com to your URL! Now we can test the Nginx config, restart Nginx, and use Certbot to generate certificates,
At this point, Certbot will ask if you want to redirect HTTP traffic to HTTPS traffic. I said yes to this but you don’t have too (but you probably should!).
Now you should be able to go to https://jenkins.example.com and everything should be ready to go!
Hope this helps :)
Kerren