Install and configure Jenkins with Nginx as a reverse proxy on CentOS

Jenkins is an open source continuous integration tool written in Java. The project was forked from Hudson after a dispute with Oracle.

Jenkins provides continuous integration services for software development. It is a server-based system running in a servlet container such as Apache Tomcat. It supports SCM tools including AccuRev, CVS, Subversion, Git, Mercurial, Perforce, Clearcase and RTC, and can execute Apache Ant and Apache Maven based projects as well as arbitrary shell scripts and Windows batch commands. The primary developer of Jenkins is Kohsuke Kawaguchi. Released under the MIT License, Jenkins is free software.

Builds can be started by various means, including being triggered by commit in a version control system, by scheduling via a cron-like mechanism, by building when other builds have completed, and by requesting a specific build URL.
Login to your VPS via SSH
ssh user@vps_IP
Make sure your server is fully up to date:
yum update

Your next step is to install Nginx along some needed dependencies and the nano text editor so you can edit some config files. Of course, you can use your favorite text editor.
Install the official Nginx repository for CentOS 7 and then install Nginx, nano etc… Use the below commands to do that:
# rpm -Uvh

# yum install nginx wget nano
Start Nginx and enable it to start on boot:
# systemctl start nginx

# systemctl enable nginx
Now create a host directive for the domain from which you will access Jenkins. Open a file, let’s say called 'your_domain.conf' in the '/etc/nginx/conf.d/' directory:
# nano /etc/nginx/conf.d/your_domain.conf
Paste the following:
upstream jenkins {

server {
    listen      80 default;

    access_log  /var/log/nginx/jenkins.access.log;
    error_log   /var/log/nginx/jenkins.error.log;

    proxy_buffers 16 64k;
    proxy_buffer_size 128k;

    location / {
        proxy_pass  http://jenkins;
        proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
        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 https;

Replace the '' value with your own domain, save and close the file.
Test if the Nginx configuration is OK:
# nginx -t
If everything is OK, restart Nginx for the changes to take effect:
# service nginx restart
Since Jenkins is built with Java, let’s install it with the yum package manager:
# yum install java
# java -version

openjdk version "1.8.0_71"
OpenJDK Runtime Environment (build 1.8.0_71-b15)
OpenJDK 64-Bit Server VM (build 25.71-b15, mixed mode)

Download the Jenkins repo and install Jenkins with the following commands:
# wget -O /etc/yum.repos.d/jenkins.repo

# rpm --import

# yum install jenkins
Start the Jenkins server and enable it to start on boot with:

# service jenkins start

# systemctl enable jenkins
Congratulations, you have successfully installed Jenkins..

About Author:

I am a Linux Administrator and Security Expert with this site i can help lot's of people about linux knowladge and as per security expert i also intersted about hacking related news.TwitterFacebook

Newer Post
Older Post


Post a Comment