How to Setup Jenkins with SSL with Apache Reverse Proxy on Ubuntu 18.04. By default Jenkins listens on port 8080 with it’s in-built web server. But it is necessary to secure Jenkins with SSL for protecting the sensitive data.

In this tutorial you are going to learn how to setup Apache as a reverse proxy to Jenkins on Ubuntu 18.04 on Google Cloud.

This setup is tested on Google Cloud and it will pretty run the same on any Linux distributions.


Install Apache

Install Apache with the following command.

sudo apt install apache2

This command will install Apache on your VM instance.

Setup Firewall

Once Apache is installed you can configure firewall, Apache registers itself with ufw. So, you can allow the necessary ports and enable ufw.

sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'

Make sure you have added rules for SSH port 22, if you haven’t done this you cannot access the SSH. Once you have verified you can enable UFW.

sudo ufw enable

Configure Apache for Jenkins

Enable Apache modules.

a2enmod proxy
a2enmod proxy_http
a2enmod headers

Now it’s time to configure Apache as a reverse proxy for Jenkins.

Remove the default Apache configuration.

sudo a2dissite 000-default

Create a new configuration for Jenkins.

sudo nano /etc/apache2/sites-available/jenkins.conf

Configuration for Jenkins on Subdomain

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerAlias jenkins.yourdomainnamecom

      Order deny,allow
      Allow from all

    ProxyPass         / nocanon
    ProxyPassReverse  /
    ProxyPassReverse  /

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

Paste this new configuration setting and hit Ctrl+X followed by Y to save the file.

Configuration for Jenkins on Sub-directory

Paste this new configuration setting and hit Ctrl+X followed by Y to save the file.

<Virtualhost *:80>

    ProxyRequests     Off
    ProxyPreserveHost On
    AllowEncodedSlashes NoDecode

        Order deny,allow
        Allow from all

    ProxyPass         /jenkins nocanon
    ProxyPassReverse  /jenkins
    ProxyPassReverse  /jenkins

Hit Ctrl + X followed by Y and Enter to save and exit the file.

Enable the configuration.

sudo a2ensite jenkins.conf

Configure Jenkins for Apache

In order to Jenkins work with Apache you need to make Jenkins to listen on localhost

sudo nano /etc/default/jenkins

Find the JENKINS_ARGS line and add --httpListenAddress= to the existing arguments.

So, the line will look similar to the one below.

JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT --httpListenAddress="

For sub-directory configuration you need to add additional argument with the directory name with --prefix

JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT --httpListenAddress= --prefix=/jenkins"

Save and exit the file. Finally restart Jenkins.

sudo systemctl restart jenkins

Check the configuration and restart Apache.

sudo apachectl configtest
sudo service apache2 restart

Now Apache is setup as a reverse proxy for Jenkins.

Install Free Let’s Encrypt SSL Certificate

sudo add-apt-repository ppa:certbot/certbot
sudo apt update
sudo apt install python-certbot-apache
sudo certbot --apache -m your-email -d -d

That’s all now you can visit your domain name in your web browser. You can see your Jenkins login page with HTTPS.


In this tutorial you have installed Apache, configured UFW, setup new reverse proxy configuration for Jenkins and installed SSL and configured Jenkins for Apache.

Write A Comment

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Where Writing Meets Entrepreneurship!

Get FREE Google Cloud Tutorials.
Please help us get 1000 likes in Facebook. Thank You!

Stay Connected!

Get latest tutorials on Google Cloud and Open Source topics