How install Jenkins and Setup Authenticated ProxyPass with Apache2

How install Jenkins and Setup Authenticated ProxyPass with Apache2


Jenkins ( http://jenkins-ci.org/ ) is a great open source integration server.

You can hook it in with Gitlab to create a fully functioning deployment environment. This short tutorial shows you how to install Jenkins and setup authenticated Apache2 Proxy access to Jenkins. These steps were taken on Ubuntu 11.10 64-bit.

## Add the Jenkins Repos so that we can install it from apt-get

wget -q -O - http://pkg.jenkins-ci.org/debian/jenkins-ci.org.key | sudo apt-key add -

sudo sh -c 'echo deb http://pkg.jenkins-ci.org/debian binary/ > /etc/apt/sources.list.d/jenkins.list'

sudo apt-get update

sudo apt-get install jenkins

## Ensure the repo is updated and install Jenkins

sudo apt-get update

sudo apt-get install jenkins

## I was already using port 8081 so I changed the default listening Port

vim /etc/default/jenkins

>> HTTP_PORT=8082

## We are going to want to Proxy web requests to Jenkins to localhost:8082

## so we need to add the /jenkins prefix to our config as well..

## So, now add '--prefix=/jenkins' to the last line so it looks like...

>> JENKINS_ARGS="--webroot=/var/cache/jenkins/war --httpPort=$HTTP_PORT --ajp13Port=$AJP_PORT --prefix=/jenkins"

## You should have Apache2 webserver installed - but if not install it

## and enable necessary modules

sudo aptitude install apache2

sudo a2enmod proxy

sudo a2enmod proxy_http

sudo a2enmod vhost_alias

## We want the user to have to Authenticate with our Proxy Pass to

## localhost:8082 since it will be available on the web so we need

## to create a username/password 'database' and tell Apache where

## to look for the authenticated users

sudo htpasswd -c /etc/proxyusers.htpwd username

## Add subsequent users by doing nearly the same thing..

sudo htpasswd /etc/proxyusers.htpwd username

## Edit the Apache 2 Config file and add the following

sudo vim /etc/apache2/http.conf

>> # For Jenkins

>> RewriteEngine On

>> RewriteRule ^/jenkins(.*)$ http://localhost:8082/jenkins$1 [P,L]

>> ProxyPassReverse /jenkins http://localhost:8082/jenkins

>> ProxyRequests Off

>> <Proxy http://localhost:8082/jenkins*>

>> Order deny,allow

>> Allow from all

>> AuthType Basic

>> AuthName "Jenkins"

>> AuthUserFile /etc/proxyusers.htpwd

>> Require valid-user

>> </Proxy>

That's it now you can view jenkins from the Web and authenticate

the Proxy to localhost!

Hope this helps someone -- Happy Coding


ClassyBits 2016