Friday, March 9, 2018

How to run Jenkins behind Caddy ?

https://caddyserver.com/ : Caddy is the HTTP/2 web server with automatic HTTPS

https://jenkins.io/ : The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying and automating any project.

I have installed Jenkins in Ubuntu.
If you want to install in Ubuntu please follow the tutorial below.
http://www.fullstacktechnos.com/2018/03/how-to-install-jenkins-in-ubuntu.html

Install Caddy

1)
praja@ip-****:~/jenkins$ wget https://github.com/mholt/caddy/releases/download/v0.10.10/caddy_v0.10.10_linux_amd64.tar.gz
Saving to: ‘caddy_v0.10.10_linux_amd64.tar.gz’
caddy_v0.10.10_linux_amd64.tar.gz    100%[===================================================================>]   5.36M  1.95MB/s    in 2.7s    
2017-12-28 09:01:36 (1.95 MB/s) - ‘caddy_v0.10.10_linux_amd64.tar.gz’ saved [5617625/5617625]


2)
sudo cp caddy /usr/local/bin/

praja@ip-****:~/jenkins$ ls -lart /usr/local/bin/
total 17168
drwxr-xr-x 10 root root     4096 Nov 21 10:30 ..
drwxr-xr-x  2 root root     4096 Dec 28 09:07 .
-rwxr-xr-x  1 root root 17568553 Dec 28 09:07 caddy

3)
Once the installation is complete, please add the cap_net_bind_service capability to the Caddy binary. This capability will allow the Caddy executable to bind to a port less than 1024.

praja@ip-****:~/jenkins$ sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/caddy

4)
Create the directories where you will store the Caddy configuration file Caddyfile and SSL certificates.
The term “Caddyfile” is a plaintext configuration file used to configure how Caddy works.
This configuration file is very similar in purpose to httpd.conf in Apache or nginx.conf in Nginx.

Run the following commands:

sudo mkdir /etc/caddy
sudo chown -R root:www-data /etc/caddy
sudo mkdir /etc/ssl/caddy
sudo chown -R www-data:root /etc/ssl/caddy
sudo chmod 0770 /etc/ssl/caddy
sudo touch /etc/caddy/Caddyfile
sudo mkdir /var/www
sudo chown www-data: /var/www

5)
caddy file

This will proxy all of the root traffic from port 80 to port 8080 where our Jenkins application is running – while passing the host information that most backend applications would expect when we specify transparent.

praja@ip-****:/etc/caddy$ cat Caddyfile 
jenkins.fullstacktechnos.com {
  gzip
  proxy / :8080 {
    transparent
  }
}

sudo chown www-data:www-data Caddyfile
sudo chmod 444 Caddyfile

praja@ip-****:/etc/caddy$ ls -lart Caddyfile 
-r--r--r-- 1 www-data www-data 72 Dec 28 09:31 Caddyfile

** Change the hostname as per your hosting domain or use localhost if you are testing locally.

6)
Caddy Service File

Run the following commands:

praja@ip-****:~/jenkins/init/linux-systemd$ pwd
/home/praja/jenkins/init/linux-systemd

praja@ip-****:~/jenkins/init/linux-systemd$ ls
caddy.service  README.md

praja@ip-****:~/jenkins/init/linux-systemd$ sudo cp caddy.service /etc/systemd/system/

praja@ip-****:~/jenkins/init/linux-systemd$ sudo chown root:root /etc/systemd/system/caddy.service

praja@ip-****:~/jenkins/init/linux-systemd$ sudo chmod 744 /etc/systemd/system/caddy.service

praja@ip-****:~/jenkins/init/linux-systemd$ sudo systemctl daemon-reload

praja@ip-****:/etc/systemd/system$ sudo systemctl enable caddy.service
Created symlink from /etc/systemd/system/multi-user.target.wants/caddy.service to /etc/systemd/system/caddy.service.


praja@ip-****:/etc/systemd/system$ sudo systemctl status caddy.service
● caddy.service - Caddy HTTP/2 web server
   Loaded: loaded (/etc/systemd/system/caddy.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2017-12-28 09:50:04 UTC; 8s ago
     Docs: https://caddyserver.com/docs
 Main PID: 18390 (caddy)
    Tasks: 7
   Memory: 9.5M
      CPU: 163ms
   CGroup: /system.slice/caddy.service
           └─18390 /usr/local/bin/caddy -log stdout -agree=true -conf=/etc/caddy/Caddyfile -root=/var/tmp

Dec 28 09:50:04 ip-**** caddy[18390]: Your sites will be served over HTTPS automatically using Let's Encrypt.
...

** Now visit jenkins.<your-domain>.com. Jenkins will be served over https.

Caddy is the HTTP/2 web server with automatic HTTPS

5 comments:

  1. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us and I never get bored while reading your article because, they are becomes a more and more interesting from the starting lines until the end. good page
    Ai & Artificial Intelligence Course in Chennai
    PHP Training in Chennai
    Ethical Hacking Course in Chennai Blue Prism Training in Chennai
    UiPath Training in Chennai

    ReplyDelete
  2. Vray 6.00.05 Crack is a commercial plug-in for third-party developers' 3D computer graphics software programs.VRay Crack

    ReplyDelete