How To Run Jenkins on Port 80: 4 Different Methods Explained

Run Jenkins on Port 80

When you install Jenkins, by default the Jenkins service runs on port 8080. Also, there is no direct option to run Jenkins on port 80.

In this tutorial, we have explained the steps to setup Jenkins access on port 80.

Running Jenkins on Port 80

You can run Jenkins on port 80 using the following methods.

  1. An IP table forwarding rule.
  2. Using a reverse proxy like Nginx.
  3. Running Jenkins behind a load balancer.
  4. Using Kubernetes Ingress

We will explain all three methods. You can choose one which is suitable for your environment.

Jenkins on 80 Using IP table Forwarding Rule

This is the easiest way to access Jenkins on port 80. All you have to do is run the following IPtables fording rule.

sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

Now, you should save these rules to persist even after an IPtable or a system restart.

For Redhat-based systems, run the following.

sudo iptables-save > /etc/sysconfig/iptables

For Ubuntu-based Jenkins, execute the following command.

sudo sh -c "iptables-save > /etc/iptables.rules"

Now if you access Jenkins on port 80, IP table will automatically forward the requests to 8080.

Running Jenkins Behind Nginx Reverse Proxy

If you setting up a production Jenkins server, you can consider the Nginx reverse proxy option.

Nginx is very lightweight and it can act as the best reverse proxy for Jenkins. Follow the steps given below to run Jenkins behind an Nginx reverse proxy.

Step1: Install Nginx

sudo yum install nginx

Step 2: Open the Nginx configuration file.

sudo vi /etc/nginx/nginx.conf

Step 3: Find the following snippet in the nginx.conf file.

location / {
}

Step 4: Add the following lines between the curly braces.

Note: If you run the reverse proxy setup separately, replace 127.0.0.1 with your Jenkins server IP

proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;

Step 5: Execute the SELinux command for the Nginx reverse proxy.

sudo setsebool httpd_can_network_connect 1 -P

Step 6: Restart the Nginx server.

sudo systemctl restart nginx

Now if you will be able to access Jenkins on port 80.

Jenkins behind a load balancer

Adding a load balancer will add extra cost to the Jenkins setup.

If you are on a cloud, you can opt for a cloud-specific load balancer that will send all its port 80 traffic to the backend Jenkins 8080 port.

Using Kubernetes Ingress

If you are running Jenkins on kubernetes, you can use the ingress rules to forward port 80 to Jenkins kubernetes service endpoint.

Additionally, you can use the HTTPS ingress option if you want SSL for Jenkins.

4 Shares:
2 comments
    1. Correct! Docker makes the setup very easy. However, many organizations have not started using Docker-based apps in their workflow.

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like