- Make sure you don't have Jenkins installed from Ubuntu repositories -- you'll get problems if you try to mix it with upstream packages
apt-get purge jenkins --auto-remove
- Add the upstream Jenkins package repository
wget -q -O - https://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | apt-key add -
echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list
apt-get update
-
Install Jenkins and configure it not to be reachable directly
apt-get install jenkins echo 'JENKINS_ARGS="$JENKINS_ARGS --httpListenAddress=127.0.0.1 --ajp13ListenAddress=127.0.0.1"' >> /etc/default/jenkins service jenkins restart
-
Install Apache
apt-get install apache2
- Install the Let's Encrypt client so you can get a free SSL certificate
apt-get install augeas-lenses build-essential ca-certificates libaugeas0 libffi-dev libssl-dev python-dev python-virtualenv
virtualenv /opt/letsencrypt
/opt/letsencrypt/bin/pip install -U pip setuptools wheel
/opt/letsencrypt/bin/pip install -U letsencrypt letsencrypt-apache
- Generate an SSL certificate for your domain (replace
jenkins.example.com
with your domain and[email protected]
with your email address)
/opt/letsencrypt/bin/letsencrypt certonly -t -n --agree-tos -a apache -m [email protected] -d jenkins.example.com
- Automate Let's Encrypt certificate renewal -- create a file
/etc/cron.weekly/letsencrypt
with the following text
#!/bin/sh
/opt/letsencrypt/bin/letsencrypt renew --noninteractive
service apache2 reload
-
chmod +x /etc/cron.weekly/letsencrypt
-
Configure a virtual host for your Jenkins -- create a file
/etc/apache2/sites-available/jenkins.example.com.conf
(replacejenkins.example.com
with your domain etc. here and in all further steps)
<VirtualHost *:80>
ServerName jenkins.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/jenkins.example.com
ErrorLog /var/log/apache2/jenkins.example.com/error.log
CustomLog /var/log/apache2/jenkins.example.com/access.log combined
RewriteEngine on
RewriteRule ^/(.*)$ https://jenkins.example.com/$1 [R=301,L]
</VirtualHost>
<VirtualHost *:443>
ServerName jenkins.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/jenkins.example.com
ErrorLog /var/log/apache2/jenkins.example.com/error.log
CustomLog /var/log/apache2/jenkins.example.com/access.log combined
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/jenkins.example.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/jenkins.example.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/jenkins.example.com/chain.pem
AllowEncodedSlashes NoDecode
ProxyPreserveHost On
ProxyPass / http://localhost:8080/ nocanon
ProxyPassReverse / http://localhost:8080/
ProxyPassReverse / http://jenkins.example.com/
RequestHeader set X-Forwarded-Proto "https"
RequestHeader set X-Forwarded-Port "443"
<Proxy http://localhost:8000/>
Order deny,allow
Allow from all
</Proxy>
</VirtualHost>
- Enable the virtual host
mkdir /var/www/jenkins.example.com
mkdir /var/log/apache2/jenkins.example.com
a2enmod ssl proxy_http rewrite headers
a2ensite jenkins.example.com
service apache2 reload
- Open https://jenkins.example.com/ and continue with the setup:
- type the initial admin password from
/var/lib/jenkins/secrets/initialAdminPassword
- install the plugins you want
- create an admin user account
- you're done! start adding some projects or something