{"id":763,"date":"2021-03-03T05:04:00","date_gmt":"2021-03-03T05:04:00","guid":{"rendered":"https:\/\/blog.ngocha.biz\/?p=763"},"modified":"2021-03-03T05:04:00","modified_gmt":"2021-03-03T05:04:00","slug":"access-run-jenkins-port-80","status":"publish","type":"post","link":"https:\/\/blog.ngocha.biz\/?p=763","title":{"rendered":"How To Run Jenkins on Port 80: Different Methods Explained"},"content":{"rendered":"<p>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.<\/p>\n<p>In this tutorial, we have explained the steps to setup Jenkins access on port 80.<\/p>\n<h2 id=\"running-jenkins-on-port-80\">Running Jenkins on Port 80<\/h2>\n<p>You can run Jenkins on port 80 using the following methods.<\/p>\n<ol>\n<li>An IP table forwarding rule.<\/li>\n<li>Using a reverse proxy like Nginx.<\/li>\n<li>Running Jenkins behind a load balancer.<\/li>\n<li>Using Kubernetes Ingress<\/li>\n<\/ol>\n<p>We will explain all three methods. You can choose one which is suitable for your environment.<\/p>\n<h2 id=\"jenkins-on-80-using-ip-table-forwarding-rule\">Jenkins on 80 Using IP table Forwarding Rule<\/h2>\n<p>This is the easiest way to access Jenkins on port 80. All you have to do is run the following <a href=\"https:\/\/devopscube.com\/iptables-tutorial-beginners\/\" rel=\"noreferrer noopener\">IPtables<\/a> fording rule.<\/p>\n<pre><code>sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080<\/code><\/pre>\n<p>Now, you should save these rules to persist even after an IPtable or a system restart.<\/p>\n<p>For Redhat-based systems, run the following.<\/p>\n<pre><code>sudo iptables-save &gt; \/etc\/sysconfig\/iptables<\/code><\/pre>\n<p>For <a href=\"https:\/\/devopscube.com\/install-configure-jenkins-2-0\/\" rel=\"noreferrer noopener\">Ubuntu-based Jenkins<\/a>, execute the following command.<\/p>\n<pre><code>sudo sh -c \"iptables-save &gt; \/etc\/iptables.rules\"<\/code><\/pre>\n<p>Now if you access Jenkins on port 80, IP table will automatically forward the requests to 8080.<\/p>\n<h2 id=\"running-jenkins-behind-nginx-reverse-proxy\">Running Jenkins Behind Nginx Reverse Proxy<\/h2>\n<p>If you setting up a production Jenkins server, you can consider the Nginx reverse proxy option.<\/p>\n<p>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.<\/p>\n<p><strong>Step1:<\/strong> Install Nginx<\/p>\n<pre><code>sudo yum install nginx<\/code><\/pre>\n<p><strong>Step 2:<\/strong> Open the Nginx configuration file.<\/p>\n<pre><code>sudo vi \/etc\/nginx\/nginx.conf<\/code><\/pre>\n<p><strong>Step 3: <\/strong>Find the following snippet in the nginx.conf file.<\/p>\n<pre><code>location \/ { \n}<\/code><\/pre>\n<p><strong>Step 4:<\/strong> Add the following lines between the curly braces.<\/p>\n<div class=\"kg-card kg-callout-card kg-callout-card-grey\">\n<div class=\"kg-callout-text\"><b><strong style=\"white-space: pre-wrap;\">Note:<\/strong><\/b> If you run the reverse proxy setup separately, replace <code spellcheck=\"false\" style=\"white-space: pre-wrap;\">127.0.0.1<\/code> with your Jenkins server IP<\/div>\n<\/div>\n<pre><code>proxy_pass http:\/\/127.0.0.1:8080;\nproxy_redirect off;\nproxy_set_header Host $host;\nproxy_set_header X-Real-IP $remote_addr;\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\nproxy_set_header X-Forwarded-Proto $scheme;<\/code><\/pre>\n<p><strong>Step 5:<\/strong> Execute the SELinux command for the Nginx reverse proxy.<\/p>\n<pre><code>sudo setsebool httpd_can_network_connect 1 -P<\/code><\/pre>\n<p><strong>Step 6:<\/strong> Restart the Nginx server.<\/p>\n<pre><code>sudo systemctl restart nginx<\/code><\/pre>\n<p>Now if you will be able to access Jenkins on port 80.<\/p>\n<h2 id=\"jenkins-behind-a-load-balancer\">Jenkins behind a load balancer<\/h2>\n<p>Adding a load balancer will add extra cost to the Jenkins setup.<\/p>\n<p>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.<\/p>\n<h2 id=\"using-kubernetes-ingress\">Using Kubernetes Ingress<\/h2>\n<p>If you are <a href=\"https:\/\/devopscube.com\/setup-jenkins-on-kubernetes-cluster\/\" rel=\"noreferrer noopener\">running Jenkins on kubernetes<\/a>, you can use the ingress rules to forward port 80 to Jenkins kubernetes service endpoint.<\/p>\n<p>Additionally, you can use the HTTPS ingress option if you want <a href=\"https:\/\/devopscube.com\/configure-ssl-jenkins\/\" rel=\"noreferrer noopener\">SSL for Jenkins<\/a>.<\/p>\n<hr>\n<p><strong>Ngu\u1ed3n:<\/strong> <a href=\"https:\/\/devopscube.com\/access-run-jenkins-port-80\/\" target=\"_blank\" rel=\"noopener noreferrer\">How To Run Jenkins on Port 80: Different Methods Explained \u2014 DevOpsCube<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Source: https:\/\/devopscube.com\/access-run-jenkins-port-80\/<\/p>\n","protected":false},"author":1,"featured_media":764,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-763","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-devops"],"_links":{"self":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/763","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=763"}],"version-history":[{"count":0,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/posts\/763\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=\/wp\/v2\/media\/764"}],"wp:attachment":[{"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=763"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=763"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ngocha.biz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=763"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}